0

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]?なぜ私は奇妙な出力を得るのですか?

4

1 に答える 1