Issues compiling COUPLE/simple.c

Hello,

I have created my own C code to model a metal lattice, but I am relying on LAMMPS to compute forces and potentials for each atom using the EAM potential (pair_style eam).

I am trying to compile the LJ example COUPLE/simple.c, however I am running into the following issues.

For compilation, the gcc command listed in the example did not work, but mpicc did work. Would this syntax still be OK?

mpicc -L/Desktop/lammps/src -c simple.c -llammps -lfftw -lmpich -lmpl -lpthread -lstdc++ -o simpleC

mpirun -np 1 simpleC 1 in.lj

In the header, I commented out the following line. What libraries would I need for this LJ example, and what would I later need when implementing the EAM potential?

//#include "library.h"

I am getting the following warnings after compilation using the mpicc line:

simple.c: In function ‘main’:
simple.c:75:20: warning: implicit declaration of function ‘lammps_open’ [-Wimplicit-function-declaration]
if (lammps == 1) lammps_open(0,NULL,comm_lammps,&lmp);
**^~~~~~~~~~~**

I am also getting the following error when I try to run the program using the mpirun line for both 1 and 2 processors:

Hello,

I have created my own C code to model a metal lattice, but I am relying on
LAMMPS to compute forces and potentials for each atom using the EAM
potential (pair_style eam).

I am trying to compile the LJ example COUPLE/simple.c, however I am
running into the following issues.

For compilation, the gcc command listed in the example did not work, but
mpicc did work. Would this syntax still be OK?

*mpicc -L/Desktop/lammps/src -c simple.c -llammps -lfftw -lmpich -lmpl
-lpthread -lstdc++ -o simpleC*

​yes, and no. you should not need to like to -lmpich and -lmpi, as those
are automatically added by mpicc.
you are missing the -I flag to the LAMMPS src folder so mpicc can find the
library.h include file. ​

*mpirun -np 1 simpleC 1 in.lj*

In the header, I commented out the following line. What libraries would I
need for this LJ example, and what would I later need when implementing the
EAM potential?

*//#include "library.h"*
*​*

​you should not do that. this header file contains all the prototypes and

data structures for the library interface.​

I am getting the following warnings after compilation using the mpicc line:

*simple.c: In function ‘main’:simple.c:75:20: warning: implicit
declaration of function ‘lammps_open’ [-Wimplicit-function-declaration]
if (lammps == 1) lammps_open(0,NULL,comm_lammps,&lmp);*

* ^~~~~~~~~~~*

​that is a direct consequence of your commenting out the library.h
include.​ it can create serious problems.

I am also getting the following error when I try to run the program using
the mpirun line for both 1 and 2 processors:

*--------------------------------------------------------------------------mpirun
was unable to find the specified executable file, and thereforedid not
launch the job. This error was first reported for processrank 0; it may
have occurred for other processes as well.NOTE: A common cause for this
error is misspelling a mpirun command line parameter option (remember
that mpirun interprets the first unrecognized command line token as
the executable).Node: anne-HP-NotebookExecutable:
simpleC--------------------------------------------------------------------------*

​that is because you are ignoring the fact, that the local directory is not
in the $PATH search path for executables (for security reasons)​.

in summary, none of these are LAMMPS issues, but an indication of lack of
experience with compiling/programming and linux/unix environments.
you'll be better off and get help faster, if you consult somebody local
that is familiar with these.

axel.

Hi Axel, I am just following up errors compiling examples/COUPLE/simple/simple.c after better understanding how to compile in linux.

Using the provided code in the README file…

gcc -I/home/sjplimp/lammps/src -c simple.c
*gcc -L/home/sjplimp/lammps/src simple.o *
-llammps -lfftw -lmpich -lmpl -lpthread -lstdc++ -o simpleC

…I have modified it as follows, because gcc was not working. And, as you previously said in your email, the mpi flags were not needed. I am also using ubuntu, and successfully built liblammps_ubuntu.a. The following code is run from the lammps src folder, including the library and the simple.c file.

mpicc -I/$HOME/Desktop/lammps/src -c simple.c
*mpicc -L/$HOME/Desktop/lammps/src simple.o *
-llammps_ubuntu -lfftw -lpthread -lstdc++ -o simpleC -lm

The following is the error that I am getting. Could you please let me know if there is some flag or library that is still missing? I am stuck on what exactly it is.

Thank you,
Anne

//home/anne/Desktop/lammps/src/liblammps_ubuntu.a(library.o): In function MPI::Op::Init(void (*)(void const*, void*, int, MPI::Datatype const&), bool)': /usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/ompi/mpi/cxx/op_inln.h:122: undefined reference to ompi_mpi_cxx_op_intercept’
//home/anne/Desktop/lammps/src/liblammps_ubuntu.a(library.o): In function MPI::Intracomm::Intracomm(ompi_communicator_t*)': /usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/ompi/mpi/cxx/intracomm_inln.h:23: undefined reference to MPI::Comm::Comm()’
//home/anne/Desktop/lammps/src/liblammps_ubuntu.a(library.o): In function MPI::Intracomm::Intracomm()': /usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/ompi/mpi/cxx/intracomm.h:25: undefined reference to MPI::Comm::Comm()’
/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/ompi/mpi/cxx/intracomm.h:25: undefined reference to MPI::Comm::Comm()' /usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/ompi/mpi/cxx/intracomm.h:25: undefined reference to MPI::Comm::Comm()’
/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/ompi/mpi/cxx/intracomm.h:25: undefined reference to MPI::Comm::Comm()' //home/anne/Desktop/lammps/src/liblammps_ubuntu.a(library.o):/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/ompi/mpi/cxx/intracomm.h:25: more undefined references to MPI::Comm::Comm()’ follow
//home/anne/Desktop/lammps/src/liblammps_ubuntu.a(library.o):(.data.rel.ro._ZTVN3MPI8DatatypeE[_ZTVN3MPI8DatatypeE]+0x78): undefined reference to MPI::Datatype::Free()' //home/anne/Desktop/lammps/src/liblammps_ubuntu.a(library.o):(.data.rel.ro._ZTVN3MPI3WinE[_ZTVN3MPI3WinE]+0x48): undefined reference to MPI::Win::Free()’
//home/anne/Desktop/lammps/src/liblammps_ubuntu.a(image.o): In function LAMMPS_NS::Image::write_JPG(_IO_FILE*)': /home/anne/Desktop/lammps/src/Obj_ubuntu/../image.cpp:1000: undefined reference to jpeg_std_error’
/home/anne/Desktop/lammps/src/Obj_ubuntu/…/image.cpp:1001: undefined reference to jpeg_CreateCompress' /home/anne/Desktop/lammps/src/Obj_ubuntu/../image.cpp:1002: undefined reference to jpeg_stdio_dest’
/home/anne/Desktop/lammps/src/Obj_ubuntu/…/image.cpp:1008: undefined reference to jpeg_set_defaults' /home/anne/Desktop/lammps/src/Obj_ubuntu/../image.cpp:1009: undefined reference to jpeg_set_quality’
/home/anne/Desktop/lammps/src/Obj_ubuntu/…/image.cpp:1010: undefined reference to jpeg_start_compress' /home/anne/Desktop/lammps/src/Obj_ubuntu/../image.cpp:1015: undefined reference to jpeg_write_scanlines’
/home/anne/Desktop/lammps/src/Obj_ubuntu/…/image.cpp:1018: undefined reference to jpeg_finish_compress' /home/anne/Desktop/lammps/src/Obj_ubuntu/../image.cpp:1019: undefined reference to jpeg_destroy_compress’
//home/anne/Desktop/lammps/src/liblammps_ubuntu.a(image.o): In function LAMMPS_NS::Image::write_PNG(_IO_FILE*)': /home/anne/Desktop/lammps/src/Obj_ubuntu/../image.cpp:1031: undefined reference to png_create_write_struct’
/home/anne/Desktop/lammps/src/Obj_ubuntu/…/image.cpp:1035: undefined reference to png_create_info_struct' /home/anne/Desktop/lammps/src/Obj_ubuntu/../image.cpp:1041: undefined reference to png_set_longjmp_fn’
/home/anne/Desktop/lammps/src/Obj_ubuntu/…/image.cpp:1046: undefined reference to png_init_io' /home/anne/Desktop/lammps/src/Obj_ubuntu/../image.cpp:1047: undefined reference to png_set_compression_level’
/home/anne/Desktop/lammps/src/Obj_ubuntu/…/image.cpp:1049: undefined reference to png_set_IHDR' /home/anne/Desktop/lammps/src/Obj_ubuntu/../image.cpp:1065: undefined reference to png_set_text’
/home/anne/Desktop/lammps/src/Obj_ubuntu/…/image.cpp:1066: undefined reference to png_write_info' /home/anne/Desktop/lammps/src/Obj_ubuntu/../image.cpp:1072: undefined reference to png_write_image’
/home/anne/Desktop/lammps/src/Obj_ubuntu/…/image.cpp:1073: undefined reference to png_write_end' /home/anne/Desktop/lammps/src/Obj_ubuntu/../image.cpp:1075: undefined reference to png_destroy_write_struct’
/home/anne/Desktop/lammps/src/Obj_ubuntu/…/image.cpp:1037: undefined reference to png_destroy_write_struct' /home/anne/Desktop/lammps/src/Obj_ubuntu/../image.cpp:1042: undefined reference to png_destroy_write_struct’
//home/anne/Desktop/lammps/src/liblammps_ubuntu.a(fft3d.o): In function fft_3d': /home/anne/Desktop/lammps/src/Obj_ubuntu/../fft3d.cpp:117: undefined reference to fftw_execute_dft’
/home/anne/Desktop/lammps/src/Obj_ubuntu/…/fft3d.cpp:156: undefined reference to fftw_execute_dft' /home/anne/Desktop/lammps/src/Obj_ubuntu/../fft3d.cpp:195: undefined reference to fftw_execute_dft’
/home/anne/Desktop/lammps/src/Obj_ubuntu/…/fft3d.cpp:117: undefined reference to fftw_execute_dft' /home/anne/Desktop/lammps/src/Obj_ubuntu/../fft3d.cpp:156: undefined reference to fftw_execute_dft’
//home/anne/Desktop/lammps/src/liblammps_ubuntu.a(fft3d.o):/home/anne/Desktop/lammps/src/Obj_ubuntu/…/fft3d.cpp:195: more undefined references to fftw_execute_dft' follow //home/anne/Desktop/lammps/src/liblammps_ubuntu.a(fft3d.o): In function fft_3d_create_plan’:
/home/anne/Desktop/lammps/src/Obj_ubuntu/…/fft3d.cpp:567: undefined reference to fftw_plan_many_dft' /home/anne/Desktop/lammps/src/Obj_ubuntu/../fft3d.cpp:572: undefined reference to fftw_plan_many_dft’
/home/anne/Desktop/lammps/src/Obj_ubuntu/…/fft3d.cpp:577: undefined reference to fftw_plan_many_dft' /home/anne/Desktop/lammps/src/Obj_ubuntu/../fft3d.cpp:582: undefined reference to fftw_plan_many_dft’
/home/anne/Desktop/lammps/src/Obj_ubuntu/…/fft3d.cpp:587: undefined reference to fftw_plan_many_dft' //home/anne/Desktop/lammps/src/liblammps_ubuntu.a(fft3d.o):/home/anne/Desktop/lammps/src/Obj_ubuntu/../fft3d.cpp:592: more undefined references to fftw_plan_many_dft’ follow
//home/anne/Desktop/lammps/src/liblammps_ubuntu.a(fft3d.o): In function fft_1d_only': /home/anne/Desktop/lammps/src/Obj_ubuntu/../fft3d.cpp:828: undefined reference to fftw_execute_dft’
/home/anne/Desktop/lammps/src/Obj_ubuntu/…/fft3d.cpp:833: undefined reference to fftw_execute_dft' /home/anne/Desktop/lammps/src/Obj_ubuntu/../fft3d.cpp:838: undefined reference to fftw_execute_dft’
/home/anne/Desktop/lammps/src/Obj_ubuntu/…/fft3d.cpp:828: undefined reference to fftw_execute_dft' /home/anne/Desktop/lammps/src/Obj_ubuntu/../fft3d.cpp:833: undefined reference to fftw_execute_dft’
//home/anne/Desktop/lammps/src/liblammps_ubuntu.a(fft3d.o):/home/anne/Desktop/lammps/src/Obj_ubuntu/…/fft3d.cpp:838: more undefined references to `fftw_execute_dft’ follow