Parallel processing 进程同步

Parallel processing 进程同步,parallel-processing,mpi,Parallel Processing,Mpi,我仍然对使用MPI实现我的程序感到困惑。这是我的例子: import mpi.*; public class HelloWorld { static int me; static Object [] o = new Object[1]; public static void main(String args[]) throws Exception { //10 processes were started: -np 10 MPI.In

我仍然对使用MPI实现我的程序感到困惑。这是我的例子:

 import mpi.*;
 public class HelloWorld {
     static int me;
     static Object [] o = new Object[1];
     public static void main(String args[]) throws Exception {
       //10 processes were started: -np 10
       MPI.Init(args);
       me = MPI.COMM_WORLD.Rank();
       if(me == 0) {
            o[0] = generateRandBoolean(0.5);
            for(int i=1; i<10;i++) 
                MPI.COMM_WORLD.Isend(o, 0, 1, MPI.OBJECT, i,0);
            if((Boolean)o[0])
                MPI.COMM_WORLD.Barrier();
        } else {

            (new HelloWorld()).work();
        }
        MPI.Finalize();
    }

    public void work() {
        //do some calculation
            //for some reason, the 10th process
        //will not be needed
            if(me == 9) 
            return;

        //some times, the rest of the
        //processes have to be synchronized
        Request rreq = MPI.COMM_WORLD.Irecv(o, 0, 1, MPI.OBJECT, MPI.ANY_SOURCE, 0);
        rreq.Wait();
        if((Boolean)o[0])
            MPI.COMM_WORLD.Barrier();
    }

    public static boolean generateRandBoolean(double p) {
        return (Math.random() < p);
    }
}
导入mpi.*;
公共类HelloWorld{
静态int-me;
静态对象[]o=新对象[1];
公共静态void main(字符串args[])引发异常{
//启动了10个过程:-np 10
MPI.Init(args);
me=MPI.COMM_WORLD.Rank();
如果(me==0){
o[0]=生成器布尔(0.5);

对于(int i=1;i使用MPI_屏障收集程序结束时的所有列组


在所有合理的MPI实现中,如果有任何其他进程有工作要做,则集合中的列组将旋转或产生处理器。这可能看起来很像列组消耗100%的CPU…但如果任何其他进程确实有工作要做,则会安排并允许运行。

您在哪里听说过使用MPI炣障碍是一个性能罚球?