0

I use this c++ code

#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;
}

In allmet I insert all files from metis and parmetis. Try to compile using OpenMPI with g++ compiler:

mpicxx -I path/allmet/include -L path/allmet/lib par.cpp

I get error:

undefined reference to `ParMETIS_V3_PartMeshKway'

With cmake:

cmake_minimum_required(VERSION 2.8.9)
project (MetisTest)
find_package(MPI)
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
include_directories("path/allmet/include")
link_directories("path/allmet/lib")
add_executable(metisTest par.cpp)
target_link_libraries(metisTest ${MPI_C_LIBRARIES})

I have:

undefined reference to `ParMETIS_V3_PartMeshKway'
in function `MPI::Intracomm::Intracomm()':
undefined reference to `MPI::Comm::Comm()'

and many others So what I can do? Metis work perfect but with parmetis I can't do anything. Ubuntu 18.10, gcc 8.2.0.

HERT
  • 63
  • 8

1 Answers1

0

You also need to link against Parmetis itself:

target_link_libraries(metisTest ${MPI_C_LIBRARIES} ${MPI_CXX_LIBRARIES} ${PARMETIS_LIBS})

Do note that:

link_directories("path/allmet/lib")

Is irrelevant for the link. If you still want to use the command line, you need:

mpicxx -Ipath/allmet/include -Lpath/allmet/lib -lparmetis -lmetis par.cpp
Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62
  • I try mpicxx -Ipath/allmet/include -Lpath/allmet/lib -lparmetis -lmetis par.cpp and get the same error. With cmake cmake_minimum_required(VERSION 2.8.9) project (MetisTest) find_package(MPI) include_directories(SYSTEM ${MPI_INCLUDE_PATH}) include_directories("/home/kyll/Documents/allmet/include") link_directories("/home/kyll/Documents/allmet/lib") add_executable(metisTest par.cpp) target_link_libraries(metisTest ${MPI_C_LIBRARIES} metis parmetis) | openmpi-2.1.2/lib/libmpi.so: undefined reference to symbol '__c_mzero4' /// libpgc.so: error adding symbols: DSO missing from command line – HERT Feb 04 '19 at 15:50
  • Seems like you are using PGI and not gcc? Try building everything with gcc first. – Matthieu Brucher Feb 04 '19 at 15:54
  • I used g++ initially. – HERT Feb 04 '19 at 16:01
  • There is a consistency issue here. The missing symbols are very different than what you had in your original question. These are implementation details fromt he PGI compiler. Start by providing your full stack with gcc only, not ounce of PGI, just to validate that you have a simple workflow. – Matthieu Brucher Feb 04 '19 at 16:22
  • I use g++ with Open MPI so i try run command line without and with -lparmetis -lmetis and get error: undefined reference to `ParMETIS_V3_PartMeshKway' in both cases. In cmake I add metis parmetis at: target_link_libraries(metisTest ${MPI_C_LIBRARIES}) and get new errors: with missing symbols and DSO. – HERT Feb 04 '19 at 16:30
  • You have to add the parmetis libraries (the fact that you have a link error with or without -lparmetis doesn't make any sense, you would get differnt error messages), and you need to have a parmetis version compiled with gcc. parmetis is built as a static library, isn't it? – Matthieu Brucher Feb 04 '19 at 16:33
  • The C compiler identification is PGI 18.10.1||| The CXX compiler identification is GNU 8.2.0||| C++ use GNU and I reinstall parmetis and get same errors – HERT Feb 04 '19 at 16:50
  • Well, don't use PGI, as I've said. There are obviously pieces missing in your explanation, a standard metis/parmetis, built with gcc/g++ + MPI also built with gcc/g++ + your code works with what I gave you. – Matthieu Brucher Feb 04 '19 at 16:50
  • I don't know these missing libraries. Look the symbols up and figure out which libraries are missing (http://glaros.dtc.umn.edu/gkhome/node/842). – Matthieu Brucher Feb 04 '19 at 17:22
  • OK, you used metis before parmetis. Metis has to be last. – Matthieu Brucher Feb 04 '19 at 17:23