我尝试使用 ParMETIS 在我的 4 核笔记本上对我的 8 个节点未加权无向图进行分区,我有以下代码:
#include <cstdlib>
#include "parmetis.h"
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
int np = 4;
idx_t xadj_[3];
idx_t adjncy_[5];
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0)
{
xadj_[0] = 0;
xadj_[1] = 2;
xadj_[2] = 5;
adjncy_[0] = 4;
adjncy_[1] = 1;
adjncy_[2] = 0;
adjncy_[3] = 5;
adjncy_[4] = 2;
}
if (rank == 1)
{
xadj_[0] = 0;
xadj_[1] = 3;
xadj_[2] = 5;
adjncy_[0] = 1;
adjncy_[1] = 6;
adjncy_[2] = 3;
adjncy_[3] = 2;
adjncy_[4] = 7;
}
if (rank == 2)
{
xadj_[0] = 0;
xadj_[1] = 2;
xadj_[2] = 5;
adjncy_[0] = 5;
adjncy_[1] = 0;
adjncy_[2] = 6;
adjncy_[3] = 1;
adjncy_[4] = 4;
}
if (rank == 3)
{
xadj_[0] = 0;
xadj_[1] = 3;
xadj_[2] = 5;
adjncy_[0] = 7;
adjncy_[1] = 2;
adjncy_[2] = 5;
adjncy_[3] = 3;
adjncy_[4] = 6;
}
idx_t *xadj = xadj_;
idx_t *adjncy = adjncy_;
idx_t vtxdist_[] = {0,2,4,6,8};
idx_t *vtxdist = vtxdist_;
idx_t *vwgt = NULL;
idx_t *adjwgt = NULL;
idx_t wgtflag_[] = {0};
idx_t *wgtflag = wgtflag_;
idx_t numflag_[] = {0};
idx_t *numflag = numflag_;
idx_t ncon_[] = {1};
idx_t *ncon = ncon_;
idx_t nparts_[] = {np};
idx_t *nparts = nparts_;
real_t *tpwgts = new real_t[np*ncon[0]]; for(int i=0; i<np*ncon[0]; i++) {tpwgts[i] = 1.0/np;}
real_t ubvec_[] = {1.05};
real_t *ubvec = ubvec_;
idx_t options_[] ={0, 0, 0};
idx_t *options =options_;
idx_t *edgecut;
idx_t part[8];
MPI_Comm comm_val=MPI_COMM_WORLD;
MPI_Comm *comm=&comm_val;
ParMETIS_V3_PartKway(vtxdist,xadj,adjncy, vwgt, adjwgt, wgtflag, numflag, ncon, nparts, tpwgts, ubvec, options, edgecut, part, comm);
MPI_Barrier(comm_val);
printf("Processor %d --- %d\n", rank,*edgecut);
for (int i = rank*2 ; i < rank*2+2; i++)
{
printf("%d\n",part[i]);
}
MPI_Finalize();
return 0;
}
对于每个等级(核心),我设置了分布式 CSR 格式并尝试获得结果,但得到这个:
Processor 0 --- 6
0
0
Processor 1 --- 6
0
0
Processor 2 --- 6
2101207184
22080
Processor 3 --- 6
1904762080
22069
我做错了什么?也许是因为共享内存或每个核心都有自己的部分[8]?为什么我得到如此奇怪的输出?