ParMETIS:对'ParMETIS_V3_PartMeshKway'的未定义引用

时间:2016-09-09 18:26:14

标签: c++ metis

我已经构建并安装了parmetis-4.0.3并编写了一个简单的代码来测试它。但是我收到一个错误说:"未定义引用`ParMETIS_V3_PartMeshKway'"

我的C代码是:

#include <iostream>
#include "parmetis.h"

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

  MPI_Init(&argc, &argv);

  int np = 3;  int ne = 36;

  idx_t *elmdist = new idx_t[np+1];  for (int i=0; i<np+1; i++) {elmdist[i] = (i-1)*ne/np;} elmdist[np] = ne;

  idx_t *eptr = new idx_t[ne+1];   for (int i=0; i<ne+1; i++) {eptr[i] = (i-1)*3;}

  idx_t eind_[] = {13, 14, 15,
           13, 16, 17,
           2, 17, 6,
           4, 15, 10,
           13, 15, 19,
           13, 17, 18,
           13, 19, 16,
           13, 18, 14,
           1, 5, 16,
           3, 9, 14,
           7, 8, 18,
           11, 12, 19,
           1, 20, 12,
           3, 21, 8,
           7, 18, 23,
           11, 19, 22,
           2, 23, 17,
           4, 22, 15,
           14, 25, 15,
           16, 24, 17,
           15, 22, 19,
           17, 23, 18,
           1, 16, 20,
           3, 14, 21,
           5, 24, 16,
           9, 25, 14,
           16, 19, 20,
           14, 18, 21,
           6, 17, 24,
           10, 15, 25,
           5, 6, 24,
           9, 10, 25,
           8, 21, 18,
           12, 20, 19,
           2, 7, 23,
           4, 11, 22};
  idx_t *eind = eind_;

  idx_t *elmwgt = 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 ncommonnodes_[] = {2};
  idx_t *ncommonnodes = ncommonnodes_;

  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=NULL;

  idx_t *part=NULL;

  MPI_Comm *comm=NULL;

  ParMETIS_V3_PartMeshKway(elmdist, eptr, eind, elmwgt, wgtflag, numflag, ncon, ncommonnodes, nparts, tpwgts, ubvec, options, edgecut, part, comm);

  MPI_Finalize();
  return 0;
}

我的makefile是:

ParMETIS_INCLUDES = ${cpp_libraries}/parmetis/include
METIS_INCLUDES = ${cpp_libraries}/metis/include

INCLUDES = -I${ParMETIS_INCLUDES} -I${METIS_INCLUDES}
LFLAGS =  -L${ParMETIS_INCLUDES} -L${METIS_INCLUDES}

CC = mpic++

parmetis_try: parmetis_try.cpp
    ${CC}  -Wall -g $(INCLUDES) -o parmetis_try.out parmetis_try.cpp $(LFLAGS)

clean:
    rm *.o *.out *~

如果我在命令行中键入make,它将显示以下错误消息:

mpic++  -Wall -g -I/l/yangsong/Library/parmetis/include -I/l/yangsong/Library/metis/include -o parmetis_try.out parmetis_try.cpp -L/l/yangsong/Library/parmetis/include -L/l/yangsong/Library/metis/include
/tmp/ccmrGrI2.o: In function `main':
/l/yangsong/Simulation/VTURP/depreciated/parmetis_try/parmetis_try.cpp:85: undefined reference to `ParMETIS_V3_PartMeshKway'
collect2: error: ld returned 1 exit status
make: *** [parmetis_try] Error 1

起初我想也许我没有成功安装parmetis。但是如果我在ParMETIS_V3_PartMeshKway文件中注释掉.cpp的行,它将成功编译。另外,如果我输入nm parmetis/lib/libparmetis.so | grep Kwa | grep Mes,则会显示:

000000000001b570 T libparmetis__CheckInputsPartMeshKway
0000000000013e80 T ParMETIS_V3_PartMeshKway

所以我认为parmetis已成功安装。有没有想过为什么我收到此错误消息?

1 个答案:

答案 0 :(得分:2)

我不是编写makefile的专家,但我认为你的错误来自这个文件。如果我是正确的你忘了链接梅蒂斯。此外,-L标志给出了库目录。我想par_metis lib不在include文件夹中。

我用metis自己重建一个makefile,它以这种方式工作:

all: metis

main.o: main.cpp
   clang++ -Wall -I/usr/local/include -c main.cpp

metis: main.o
   clang++ -Wall main.o -o metis -L/usr/local/lib -lmetis

因为我不是make的专家,而且他们有很多错误来源,所以我更喜欢CMake而不是makefile。在这个post中,我给出了一个cmake示例。使用parmetis库替换metis应该很容易。 我希望这个答案可以帮助你和梅蒂斯好运! :)