Suppose I have a large input file.
Suppose this file has items I would like to process in parallel.
std::vector<std::string> items(100000,"");
for(int i = 0; i < 1000000; i++)
items[i] = pop_item(file);
Next, I would like to speed up processing by processing these items in parallel with MPI:
std::vector<MyObj> processed_items(100000); // pseudo-code, i handle the memory mallocing
int size; rank;
MPI_INIT();
MPI_Comm_size(MPI_COMM_WORLD,&size);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
for(i = rank; i < 100000; i += size)
processed_items[i] = process_item(items[i]);
MPI_FINALIZE();
Ok great, it works.
Now, I would like to do it over and over again within a while loop:
while(!done){
done = fill_items(&items, file);
MPI_INIT();
...;
MPI_FINALIZE();
print_items(&processed_items);
}
However, I fail with "error: mpi_init called after mpi finalize invoked."
What is the expected way for me to handle this in MPI?