0

因此,在我将数据(clusters[10][5] 2d array)Bcast 到每个其他进程之后,然后当每个进程计算其新的本地值时,我想将它们发送回进程 0。
但有时会丢失一些数据(取决于集群的数量)或数据不等于我在发送过程中拥有的数据。我不知道为什么,但是 recvcount 和 recvcount 的最大值需要除以大小或某个因子,它们不能是数组大小(10 或 10*5 - 元素数)。如果我把它的全尺寸,例如 cluster.lenght(10) 它说 indexoutofbounce 19 如果我运行更多的进程(mpjrun.bat -np 11 name)更高的索引出现在 outofbounce 并且它总是上升或下降 2更高/更低的编号 进程数(例如,我使用 5 个进程并获得跳出 9,然后下一次运行使用 6 并获得 11)。

有人可以解释为什么 Gather 的计数与进程数有关,或者为什么它不能接受数组大小?

而且程序在数据计算正确后也没有结束,只有当我使用 1 个进程时它才会结束,否则它会退出循环,然后在终端上打印一些东西,然后我有 MPI.finalize 但什么也没有发生并且我有 Ctrl+c 来终止 bat 作业,所以我可以再次使用终端。

clusterget 变量设置为集群数*进程大小,以便它存储来自其他进程的所有新集群,这样我就可以在第一个进程中使用它们,所以问题不在 clusterget 变量中,或者可能是它?由于实际上没有任何关于通过 2d 浮点数组发送的记录(是的,我需要使用 MPI.OBJECT,因为如果我使用浮点,java 不喜欢浮点,它说浮点不能转换为浮点)。

 MPI.COMM_WORLD.Bcast(clusters, 0, clusters.length, MPI.OBJECT, 0);
//calculate and then send back to 0

 MPI.COMM_WORLD.Gather(clusters, 0, clusters.length / size, MPI.OBJECT, clusterget, 0, clusters.length / size, MPI.OBJECT, 0);

            if (me == 0) {

                for (int j = 0; j < clusters.length; j++) {   //adds clusters from each other process to the first ones
                    for (int i = 0; i < size - 1; i++) { 
                        System.out.println(clusterget[j+i*cluster][4]+" tock "+clusters[j][4]);
                        clusters[j][2] += clusterget[j + i * cluster][2]; //dodaj
                        clusters[j][3] += clusterget[j + i * cluster][3];
                        clusters[j][4] += clusterget[j + i * cluster][4];
                    }
                }
            }

总结:每个进程的数据与收集后收集的数据不同,我无法将二维浮点数组的完整大小放入其中。

4

1 回答 1

0

我已将收集更改为发送和接收,它可以工作,我需要添加一个屏障,以便数据在发送前同步。但这仅适用于 2 个进程。

     MPI.COMM_WORLD.Barrier();
            if (me != 0){
                MPI.COMM_WORLD.Send(clusters,0,clusters.length,MPI.OBJECT,0,MPI.ANY_TAG);
            }

            if (me == 0) {
                for (int i = 1; i < size; i++) {
  MPI.COMM_WORLD.Recv(clusterget,0,clusters.length,MPI.OBJECT,i,MPI.ANY_TAG);
                    for (int j = 0; j < clusters.length; j++) {
                        clusters[j][2] += clusterget[j][2]; 
                        clusters[j][3] += clusterget[j][3];
                        clusters[j][4] += clusterget[j][4];
                    }
                }
于 2021-05-16T09:03:33.503 回答