I have built and installed parmetis-4.0.3 and wrote a simple code to test it. But I am getting an error saying: "undefined reference to `ParMETIS_V3_PartMeshKway'"
The C code I have is:
#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;
}
The makefile I have is:
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 *~
If I type make
in the command line, it will show the following error message:
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
At first I thought maybe I didn't install parmetis successfully. But if I comment out the line with ParMETIS_V3_PartMeshKway
in the .cpp
file, it will compile successfully. Also, if I type nm parmetis/lib/libparmetis.so | grep Kwa | grep Mes
, it shows:
000000000001b570 T libparmetis__CheckInputsPartMeshKway
0000000000013e80 T ParMETIS_V3_PartMeshKway
So I think parmetis is successfully installed. Any thought on why am I getting this error message?
i am not an expert in writting makefiles, but I think your error comes from this file. If I am correct you forget to link against metis. Moreover the -L flag gives the library dir. I suppose the par_metis lib is not in the include folder.
I reconstruct a makefile by myself with metis and it works in that way:
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
Because I am not an expert in make and their are a lot of error sources I prefer CMake over makefiles. In this post I give a cmake example. It should be easy to replace metis with the parmetis library. I hope that answer can help you and good luck with metis! :)