用mpi分配矢量行

时间:2017-01-03 11:52:36

标签: c++ mpi genetic-algorithm

我有一个遗传算法,我希望与mpi并行。我有一个我的遗传数据类型的2d向量,我想在多个节点之间分配二维矢量线块,我使用了scatterv函数,但我不知道这个函数是对的还是我没有设置正确这个函数的参数。 indivisual定义为GMC类std :: vector individual [108]中的公共参数;请帮帮我。

由于

我的代码如下:

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

GMC(GraphName, 125);
int size, rank,divided_pop_size,sum=0;

vector<vector <int>> recbuf;
int *sendcounts;     //specifying the number of elements to send to each processor
int *displs;         //Entry i specifies the displacement 
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
printf("Hello world from process %d of %d\n", rank, size);
sendcounts = new int[size];
displs = new int[size];
divided_pop_size = n_initial_pop*num_vertices / size;
for (int i = 0; i < size; i++) {
    sendcounts[i] = (divided_pop_size);

    displs[i] = sum;
    sum += sendcounts[i];
}

recbuf.resize(divided_pop_size);
if (rank == 0)
{
    read_graph();
    vertex_degrees();
    initial_population();
}

MPI_Scatterv(&individual, sendcounts, displs, MPI_INT, &recbuf, sendcounts[rank] , MPI_INT, 0, MPI_COMM_WORLD);
if (rank==0) {
    for (int i = 0; i < size; i++) {
        printf("sendcounts[%d] = %d\tdispls[%d] = %d\n", i, sendcounts[i], i, displs[i]);
    }
}
printf("%d: ", rank);
for (int i = 0; i < sendcounts[rank]; i++) {
    printf("%c\t", recbuf[i]);
}
/*
for (int i = 0; i < size; i++)
{
    //MPI_Recv()//a
    //MPI_Recv()//indivual/size

    for (int i = 0; i < divided_pop_size; i++)
    {
        //Extend_into_MaximalClique(i);
        //fitness(i);
    }
}
if (rank == 0)
    //MPI_Gatherv();
    */
MPI_Finalize();

for (int j = 0; j < n_initial_pop; j++)
{
    //manipulation_Gen();
}




return 0;

}

0 个答案:

没有答案