Building LAMMPS with GPU support

I am trying to build LAMMPS with GPU support. I could not build with Intel icpc, due to compilation issues thatI reported under a different topic. I using lammps-23Jun2022.
The code does compile with gcc. I have tried several versions of gcc, but now I failing to link.
I am using a traditional build process. I have build the libgpu library in the lib/gpu directory:
Jul 13 09:13 libgpu.a
Jul 13 09:13 Makefile.lammps
Jul 13 09:13 nvc_get_devices

Now I am building lammps, with the same gcc compiler. Several oddities:

  1. The link process tries to find libgpu in …/…/lib/gpu, but in my directory structures it should be …/lib/gpu. I have worked around this, by simply creating a link at expected location.
  2. “main” is not found when linking. Here is my verbose link command:
    mpicxx -g -v -std=c++11 -o lammps.v100 -ldl -L…/…/lib/gpu -L/nasa/intel/Compiler/2021.3.0/mkl/2021.3.0/lib/intel64 pair_table.o fix_vector.o dump_deprecated.o write_restart.o compute_temp_deform.o write_coeff.o …-lgpu -lmpi -lmkl_core -lmkl_intel_lp64 -lmkl_sequential -lcuda -lcudart -lcuda -lpthread -lmpi -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /nasa/pkgsrc/toss3/2021Q2/gcc9/lib/gcc/x86_64-redhat-linux/9.3.0/crtend.o /lib/…/lib64/crtn.o
    /lib/…/lib64/crt1.o: In function _start': (.text+0x20): undefined reference to main’
    info.o: In function LAMMPS_NS::Info::get_gpu_device_info[abi:cxx11]()': lammps-23Jun2022/src/Obj_nas.v100/../info.cpp:1152: undefined reference to lmp_gpu_device_infoabi:cxx11
  3. The routine name in libgpu is mangled:
    pfe20.gjost 86>!nm
    nm libgpu.a | grep lmp_gpu_device_info
    0000000000000550 T _Z19lmp_gpu_device_infov

So, this an dmany others are not found.
There is something not right in what I am doing or maybe something is not set up correctly on my system. I was wondering if somebody could give me a hint, based on the information I provided. Also happy to provide more. Many thanks in advance and greetings, Gabriele

If you use the traditional make build then this is correct, because the cwd is the Obj_ folder.

That usually means your machine makefile is very old and needs to be updated.

Other undefineds may be due to using different compiler versions and settings. They must be consistent throughout.

This is correct because the GPU library is compiled with c++.

Why don’t you use the CMake based build?
It keeps things consistent and makes it harder to make mistakes.

Thank you Axel. I will for now need to stick to the traditional make, long story, but that I have to do this.
What should I do to get around the incorrect location of the libgpu library? Why is the linker looking in the …/…/lib/gpu instead …/lib/gpu? How is the path being determined?
My Makefile.nas.v100 is brand new, actually. Freshly made for the new LAMMPS port. Same for the Makeifle.nas in the lib/gpu. I am using the same compilers, all the way through. Same version, everything. Should I use gcc to build the libgpu?
Rather than g++? For the Lammps build I am using nvcc, which uses gcc as the host compiler. Some files for lammps are .cpp files, so here I am using g++. I am linking with mpicxx, which invokes the g++ compiler…all the same versions. I am setting -v flag to get this info.
Thanks so much patiently dealing with my questions…Gabriele

Sorry, but this is where my help ends. If you insist on doing things your way, then you are on your own.
The way how you compile LAMMPS correctly is documented in the manual. The situation you describe is only possible if your makefiles are not correct.

Sure, it is obvious that I am doing something wrong, otherwise it would help. However, I don’t think I am doing things “my way”, as the “traditional make” is described as a valid path in the documentation. At this point I have the name mangeling, not more undefineds coming from libgpu, however, main is still not found: Just one more simple question:
Should “main.cpp” be compiled? It looks like it is in the file Makefile.list, but using my Makefile.nas.v100 it is not compiling it…maybe I am getting closer to the source of the problem?

Got it build! Hurray! I had to update my makefile to add main.o to the objects. There was a sample Makefile.mpi, should have looked at that earlier. I now have lmp_nas.v100 and liblammps_nas.v100.a. Have not tested it yet, but will take it for a spin tomorrow! Thanks again for helping. Gabriele