MPI:在完成工作后帮助另一个人

这是我的问题:

给定一个初始间隔[a,b]进行并行化并假设流程比其他流程更快,我想做一个流程,当它完成其块(工作)时,我会“帮助”另一个(j),帮助这个case意味着在它和进程i(将要帮助的那个)之间平均分割进程j的块(它仍在工作的块)。 我已经了解了这个算法,但我不知道如何使用MPI通信function(如Broadcast,Allgather,send,recv)来实现它:我想使用所有进程共享的数组“arr” &size的大小等于所有进程的数量。 arr [i] = 1表示进程i已完成工作,否则等于-1。 我将其所有元素初始化为-1,当排名“rank”的进程完成其工作时,它确实arr [rank] = 1并且等待工作进程注意它并向它发送新块。 这是我想要实现的“伪代码”:

MPI_Init ( &argc, &argv ); MPI_Comm_rank ( MPI_COMM_WORLD, &rank ); MPI_Comm_size ( MPI_COMM_WORLD, &nb_proc ); int i; int a = 0, b = max; //initial interval [a,b] to parallelize int j; arr[nb_proc]; for(j = 0; j < 10; j++) { arr[j] = -1; //initially, all processes are working } do { i = a + rank; do { if(there's a free process) // checking the array "arr" & finding at least one element that equals 1 { //Let that process be process of rank "r": arr[r] = -1; int mid = (b+i)/2; //dividing the rest of the work a = mid + rank - r; MPI_Send(a to process r); MPI_Send(b to process r); b = a-1; } /*does i-th iteration*/ i = i + p; } while(i <= b); arr[rank] = 1; //finished working and about to start waiting for new work } while(there's at least one process that's still working & if it's the case get the new work (starting a & finishing b) from it); MPI_Finalize ( ); return 0; 

我的主要问题涉及访问数组的方式以及如何确保它更新到所有进程以及所有进程在瞬间t都具有相同的数组。 非常感谢你的帮助。 提前致谢。