Adam Adam - 2 months ago 14
C Question

How to use MPI_Abort() to terminate other processors

In MPI,

MPI_Abort()
is mostly intended for aborting abnormal behaviors. In my program below, at each iteration the ROOT process checks a condition while the remaining processors wait at the
MPI_Barrier
to receive the data for the next iteration. Thus, if the threshold is met, I want the root to terminate the entire loop and also other processors should leave the loop and terminate. My question is: Does it make sense to use
MPI_Abort()
so that processors who are waiting in the barrier will terminate?

void kmeans() {

do{
// Step1: ROOT Broadcast the K centroids.
MPI_Bcast(&cluster_centroids, N, MPI_FLOAT, ROOT, MPI_COMM_WORLD);
MPI_Barrier(MPI_COMM_WORLD);

// Step2: Calculate the distances.
points_assignment(data, cluster_center);

// Step3: Update cluster centroid (Locally at each processor)
update_centroids_locally();

if(Rank == ROOT){
// Step4: ROOT checks the threshold
Flag = check_threshold(cluster_center);

if(Flag == 1){
// MPI_Abort(MPI_COMM_WORLD,0);
break;
}else{
continue;
}
}

} while(1);

}

Answer

To avoid the use of MPI_Abort, I can think two options for termination:

1) The simple one: each time broadcast a termination flag and each process will continue or stop based on that flag.

2) You could use two MPI_IBcast and MPI_Waitany. With the one MPI_IBcast you will broadcast your cluster_centroids and with the other one you will broadcast a termination flag. Each time you will check wich broadcast has been complete and based on that, each process will decide to continue or stop.

Comments