void slave(int num_threads){
long result;
long bounds[2];
MPI_Status status;
while(true){
MPI_Recv(bounds, 2, MPI_LONG, 0, MPI_ANY_TAG,
MPI_COMM_WORLD, &status);
if (status.MPI_TAG == KILL)
return;
try {
long start(bounds[0]);
long stop(bounds[1]);
... 插入线程版本 main() 中的代码 ...
MPI_Send(&count,1,MPI_LONG, 0,
0, MPI_COMM_WORLD);
}
catch (range_error e){
cout << "Exception: " << e.what() << endl;
}
}
}