使用多个mpi_bcast时出错

时间:2017-03-11 21:01:22

标签: parallel-processing mpi

我遇到3 mpi_bcast和1 mpi_scatter的问题,我的程序运行不好,mpi_scatter没有工作,globalparcsr不在节点之间分散。当我删除第二个和第三个mpi_bcast时,mpi_scatter运行良好。我想要广播和全球个人和全球适应性,然后分散globalparcsr,我的代码的一部分如下:

int malloc2dint(int ***array, int n, int m) {

/* allocate the n*m contiguous items */
int *p = (int *)malloc(n*m * sizeof(int));
if (!p) return -1;

/* allocate the row pointers into the memory */
(*array) = (int **)malloc(n * sizeof(int*));
if (!(*array)) {
    free(p);
    return -1;
}

/* set up the pointers into the contiguous memory */
for (int i = 0; i<n; i++)
    (*array)[i] = &(p[i*m]);

return 0;
}


 int main(int argc, char *argv[]) {


int size, rank, divided_pop_size, sum = 0, root = 0, procgridsize, sum2 = 0,generation=0;
int **globalindividual, **localindividual;
int *globalfitness, *localfitness;
int *globalparcsr, *localparcsr;
int **recbuf;
int *sendcounts, *parsendcount;     //specifying the number of elements to send to each processor
int *displs, *pardispls;         //Entry i specifies the displacement   
MPI_Status status;
int offset, rows;

MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);

MPI_Comm_rank(MPI_COMM_WORLD, &rank);

divided_pop_size = n_initial_pop / size;


if (rank == root)
{


    malloc2dint(&globalindividual, n_initial_pop, num_vertices);
    read_graph();

    globalfitness = (int*)malloc(n_initial_pop * sizeof(int));
    globalparcsr = (int*)malloc(n_initial_pop * sizeof(int));

    globalindividual = initial_population(globalindividual, n_initial_pop);

    for (int i = 0; i < n_initial_pop; i++) {
        printf("\n");
        for (int j = 0; j < num_vertices; j++)
            printf("%d", globalindividual[i][j]);
    }


}
for (int p = 0; p < size; p++) {

    if (rank == p) {
        malloc2dint(&localindividual,n_initial_pop + 2, num_vertices);
        localindividual = initial_population(localindividual, divided_pop_size + 2);
    }
}



    MPI_Bcast(&a[0][0], 5000 * 5000, MPI_INT, 0, MPI_COMM_WORLD);
    MPI_Barrier(MPI_COMM_WORLD);
    MPI_Bcast(&globalindividual[0][0], n_initial_pop*num_vertices, MPI_INT, 0, MPI_COMM_WORLD);

    MPI_Bcast(&globalfitness, n_initial_pop, MPI_INT, 0, MPI_COMM_WORLD);




MPI_Finalize();

return 0;
}

a是2d数组,globalindividual是2d数组,有12行8列,globalfitness是1d数组,大小为12

请帮帮我。

0 个答案:

没有答案