Adam Adam - 10 months ago 57
C Question

How to use MPI_Abort() to terminate other processors


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
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
so that processors who are waiting in the barrier will terminate?

void kmeans() {

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

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

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

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

if(Flag == 1){

} while(1);


Answer Source

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.