まず、インターネットを検索しましたが、答えが見つかりませんでした。たぶんその理由は私がMPIの初心者だからです。ここに質問があります:
まず、マスタープロセッサにtxtファイルを読み取らせたい。次に、十分な情報を取得します。しかし、この間、私は他の人に読書プロセスを待ってもらいたいです。
これが私のコードです:
int processorID;
int numberOfProcessors;
int main(int argc, char* argv[]){
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD ,&numberOfProcessors);
MPI_Comm_rank(MPI_COMM_WORLD ,&processorID);
int a, b, c;
if(MASTER){
FILE *myFile;
myFile=fopen("input.txt", "r");
fscanf(myFile, "%d", &a);
fscanf(myFile, "%d", &b);
fscanf(myFile, "%d", &c);
}
MPI_Barrier(MPI_COMM_WORLD);
if(SLAVE){
printf("%d\n" ,a);
printf("%d\n" ,processorID);
}
MPI_Finalize();
return 0;
}
MPI_Barrierを使用するべきではありませんか?たとえば、私は5つのプロセッサを持っており、0はマスターです。MPI_Barrierのおかげで、他の1-2-3-4は読み取りが完了するまで0を待つ必要はありませんか?しかし、これは機能していません。