MSMPI写入文件无法正常工作

时间:2014-03-24 15:07:18

标签: c++ c visual-c++ mpi

我想用MPI编写程序, 当程序以mpiexec.exe(在cl.exe中)运行作为调试时,它可以正常工作, 但是当它在mpiexec.exe中运行时,程序被mpiexec.exe阻止,并且在被迫关闭之前永远不会终止。

  void WriteInFile(char * str  ,bool needtonewline )
  {
    MPI_Status status;
    MPI_File file;
        //add newline in to str
    int newcharlenght , charlenght ;
    charlenght  =strlen(str);
    newcharlenght = charlenght + 1;

    char * newstr = (char  *) malloc(newcharlenght);
    newstr[0] =needtonewline ?  '\n' : ' ';

    for(int nlc = 1 ; nlc < newcharlenght ; nlc++ )
         newstr[nlc] = str[nlc-1];

     MPI_File_open(MPI_COMM_WORLD , FILE_PATH  ,  MPI_MODE_RDWR  | MPI_MODE_CREATE  , MPI_INFO_NULL ,&file);
     MPI_File_seek(file , 0 , MPI_SEEK_END);
     MPI_File_write(file , newstr , newcharlenght , MPI_CHARACTER , &status);
     MPI_File_close(&file);

     free(newstr);
   }

如何解决这个问题?

0 个答案:

没有答案