CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Main CFD Forum

MPI and parallel computation

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   April 2, 2005, 12:11
Default MPI and parallel computation
  #1
Wang
Guest
 
Posts: n/a
Hi All,

I have a problem of parallel computation. I use C language and MPI. My code can be compiled and no any error occurs. However, when I run the executable, there is error information as following:

ttjw3@oberon:~/scri/parallel> mpicc -o lbm lbm.c ttjw3@oberon:~/scri/parallel> mpirun -np 2 lbm /home/ttjw3/tem/mpich-1.2.6/bin/mpirun.ch_shmem: line 91: 18145 Segmentation fault /home/ttjw3/scri/parallel/lbm

ttjw3@oberon:~/scri/parallel>

It is appreciated to share any experience of the problem.

Thanks in advance.
  Reply With Quote

Old   April 2, 2005, 13:26
Default Re: MPI and parallel computation
  #2
Junseok Kim
Guest
 
Posts: n/a
It could be resulted from index dismatch, for example, you allocate a memory size of a matrix and routine uses larger index.

It is hard to tell the cause without looking the code itself, why don't you post the code here if it is not too lengthy. Someone may find the error.

Kim

  Reply With Quote

Old   April 3, 2005, 04:38
Default Re: MPI and parallel computation
  #3
dpshaka
Guest
 
Posts: n/a
agree with wang
  Reply With Quote

Old   April 3, 2005, 05:12
Default Re: MPI and parallel computation
  #4
zxaar
Guest
 
Posts: n/a
agree with you
  Reply With Quote

Old   April 3, 2005, 06:40
Default Re: MPI and parallel computation
  #5
Wang
Guest
 
Posts: n/a
Thanks! There are two strange problems. One is that some codes can run in my present machine, and some codes have this problem. My code has been run successfully on other machines. But it can ben run on the present machine. The below example is from MPI manual. It is simpler than my code. But there is the same problem.

ttjw3@oberon:~/jwang/tem/mpich-1.2.6/examples/basic> mpicc -o pcp pcp.c ttjw3@oberon:~/jwang/tem/mpich-1.2.6/examples/basic> ttjw3@oberon:~/jwang/tem/mpich-1.2.6/examples/basic> mpirun -np 2 pcp /home/ttjw3/jwang/tem/mpich-1.2.6/bin/mpirun.ch_shmem: line 91: 21168 Segmentation fault /home/ttjw3/jwang/tem/mpich-1.2.6/examples/basic/pcp ttjw3@oberon:~/jwang/tem/mpich-1.2.6/examples/basic>

/* pcp from SUT, in MPI */ #include "mpi.h" #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <string.h>

#define BUFSIZE 256*1024 #define CMDSIZE 80

char from_path[1024], fromname[1024],

to_path[1024], toname[1024],

origdir[1024], cmd[1024];

int main( int argc, char *argv[] ) {

int myrank, mystatus, allstatus, done, numread;

char controlmsg[CMDSIZE];

int statrc, infd, outfd;

char *c, buf[BUFSIZE];

struct stat statbuf;

FILE *infp, *outfp;

MPI_Init( &argc, &argv );

MPI_Comm_rank( MPI_COMM_WORLD, &myrank );

if (getcwd(origdir,1024) == NULL)

{

fprintf(stderr,"failed to getcwd\n");

exit(-1);

}

if ( myrank == 0 ) {

if ((c = (char*)strrchr(argv[1],'/')) != NULL)

{

strncpy(from_path,argv[1],c-argv[1]);

from_path[c-argv[1]] = '\0';

strcpy(fromname,c+1);

fromname[strlen(c)] = '\0';

chdir(from_path);

}

else

{

strcpy(fromname,argv[1]);

}

sprintf(cmd,"tar cf - %s",fromname);

if ((infp = popen(cmd,"r")) == NULL)

{

fprintf(stderr,"popen r failed\n");

strcpy( controlmsg, "exit" );

MPI_Bcast( controlmsg, CMDSIZE, MPI_CHAR, 0, MPI_COMM_WORLD );

MPI_Finalize();

exit(-1);

}

else {

infd = fileno(infp);

sprintf( controlmsg, "ready" );

MPI_Bcast( controlmsg, CMDSIZE, MPI_CHAR, 0, MPI_COMM_WORLD );

}

}

else {

MPI_Bcast( controlmsg, CMDSIZE, MPI_CHAR, 0, MPI_COMM_WORLD );

if ( strcmp( controlmsg, "exit" ) == 0 ) {

MPI_Finalize();

exit( -1 );

}

}

chdir(origdir);

if ( myrank == 0 )

strcpy( controlmsg, fromname );

MPI_Bcast( controlmsg, CMDSIZE, MPI_CHAR, 0, MPI_COMM_WORLD );

strcpy(fromname,controlmsg);

strcpy(toname,argv[2]);

statrc = stat(argv[2], &statbuf);

if (statrc >= 0)

{

if (S_ISDIR(statbuf.st_mode))

{

chdir(argv[2]);

}

}

if ((c = (char*)strrchr(argv[2],'/')) != NULL)

{

strncpy(to_path,argv[2],c-argv[2]);

to_path[c-argv[2]] = '\0';

strcpy(toname,c+1);

toname[strlen(c)] = '\0';

chdir(to_path);

}

sprintf(cmd,"tar xf - ");

if ((outfp = popen(cmd,"w")) == NULL)

{

fprintf(stderr,"popen w failed\n");

mystatus = -1;

}

else {

outfd = fileno(outfp);

mystatus = 0;

}

MPI_Allreduce( &mystatus, &allstatus, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD );

if ( allstatus == -1 ) {

if ( myrank == 0 )

fprintf(stderr,"output file %s could not be opened\n",

controlmsg );

MPI_Finalize();

return( -1 );

}

/* at this point all files have been successfully opened */

done = 0;

while ( !done ) {

if ( myrank == 0 )

numread = read( infd, buf, BUFSIZE );

MPI_Bcast( &numread, 1, MPI_INT, 0, MPI_COMM_WORLD );

if ( numread > 0 ) {

MPI_Bcast( buf, numread, MPI_BYTE, 0, MPI_COMM_WORLD );

write( outfd, buf, numread ); /* master makes a copy too */

}

else {

if ( myrank == 0 )

pclose(infp);

pclose( outfp );

done = 1;

}

}

/* if file existed but was not a dir */

if (statrc < 0 || ! S_ISDIR(statbuf.st_mode))

{

if (strcmp(fromname,toname) != 0)

{

rename(fromname,toname);

}

}

MPI_Finalize();

return 0; }

  Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in the CFX12.1 parallel computation BalanceChen ANSYS 2 July 7, 2011 10:26
HP MPI warning...Distributed parallel processing Peter CFX 10 May 14, 2011 06:17
Is Testsuite on the way or not lakeat OpenFOAM Installation 6 April 28, 2008 11:12
PROBLEM IN PARALLEL PROGRAMMING WITH MPI Niavarani Main CFD Forum 1 April 20, 2004 06:51
MPI and parallel computation Wang Main CFD Forum 7 April 15, 2004 11:25


All times are GMT -4. The time now is 20:00.