[英]How to use MPI_Abort() to terminate other processors
In MPI, MPI_Abort()
is mostly intended for aborting abnormal behaviors. 在MPI中,
MPI_Abort()
主要用于中止异常行为。 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. 在下面的程序中,每次迭代时,ROOT进程都会检查条件,而其余处理器则等待
MPI_Barrier
接收下一次迭代的数据。 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? 我的问题是:使用
MPI_Abort()
以便在屏障中等待的处理器终止会有意义吗?
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);
}
To avoid the use of MPI_Abort
, I can think two options for termination: 为了避免使用
MPI_Abort
,我可以考虑两种终止方法:
1) The simple one: each time broadcast a termination flag and each process will continue or stop based on that flag. 1)简单的方法:每次广播终止标志,并且每个进程将基于该标志继续或停止。
2) You could use two MPI_IBcast
and MPI_Waitany
. 2)您可以使用两个
MPI_IBcast
和MPI_Waitany
。 With the one MPI_IBcast
you will broadcast your cluster_centroids
and with the other one you will broadcast a termination flag. 使用一个
MPI_IBcast
您将广播cluster_centroids
;使用另一个MPI_IBcast
您将广播终止标志。 Each time you will check wich broadcast has been complete and based on that, each process will decide to continue or stop. 每次您检查广播是否已完成,并在此基础上,每个过程将决定继续还是停止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.