First of all, I have searched the Internet but could not find the answer. Maybe the reason is I am newbie on MPI. Here is the question:
Firstly I want master processor to read a txt file. Then take the enough info. But during this I want others to wait reading process.
here is my code:
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;
}
Should not I use MPI_Barrier? For example I have 5 processors, and the 0 is master. Thanks to MPI_Barrier, other 1-2-3-4 do not have to wait 0 until it finishes reading? but this is not working.