![]() |
MPI and parallel computation
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. |
Re: MPI and parallel computation
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 |
Re: MPI and parallel computation
agree with wang
|
Re: MPI and parallel computation
agree with you :)
|
Re: MPI and parallel computation
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; } |
| All times are GMT -4. The time now is 09:45. |