0
我從Using MPI-2: Advanced Features of the Message-Passing Interface中複製了以下示例,但輸出文件只是weired字符。我試圖將數據類型從int更改爲char,但輸出仍然相同。我試圖用Notepadqq和gedit等不同的程序打開輸出文件。我也嘗試用不同的文件格式打開文件,並通過零過程將空指針添加到文件末尾,但結果仍然是歪曲的字符。MPI_File_write中的奇怪字符
/* example of parallel MPI write into a single file */
#include <stdio.h>
#include "mpi.h"
#define BUFSIZE 100
int main(int argc, char **argv)
{
int i, MyRank, NumProcs, buf[BUFSIZE];
MPI_File TheFile;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &MyRank);
MPI_Comm_size(MPI_COMM_WORLD,&NumProcs);
for (i=0; i<BUFSIZE; i++)
buf[i]=MyRank*BUFSIZE+i;
MPI_File_open(MPI_COMM_WORLD, "testfile",MPI_MODE_CREATE|MPI_MODE_WRONLY,MPI_INFO_NULL, &TheFile);
MPI_File_set_view(TheFile,MyRank*BUFSIZE*sizeof(int),MPI_INT,MPI_INT,"native",MPI_INFO_NULL);
MPI_File_write(TheFile,buf,BUFSIZE,MPI_INT,MPI_STATUS_IGNORE);
// THis is my trial
if(MyRank == 0){
char nullChar = '\0';
MPI_File_write(TheFile, & nullChar , 1 , MPI_CHAR ,MPI_STATUS_IGNORE);
}
MPI_File_close(&TheFile);
MPI_Finalize();
return 0;
}
該程序不能確保過程零將運行最後..我的第一個錯誤。但是,即使我讓所有進程都以相同的方式寫入空指針,結果也是一樣的 –