• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..30-Sep-2021-

READMEH A D30-Sep-20212.5 KiB6447

in.ljH A D30-Sep-2021376 2617

liblammpsplugin.cH A D30-Sep-20213.6 KiB154105

liblammpsplugin.hH A D30-Sep-20215.9 KiB173113

log.simple.plugin.1H A D30-Sep-202112.3 KiB298265

log.simple.plugin.4H A D30-Sep-202112.4 KiB300267

simple.cH A D30-Sep-20215 KiB177105

README

1This directory has a simple C code that shows how LAMMPS can be included
2in an application as a shared library loaded at runtime. The code is
3essentially the same as in the "simple" example that links to LAMMPS
4either with a static or shared library. The purpose is to illustrate
5how another code could be built without having a LAMMPS library present
6and then load the (separately compiled) shared library.
7
8simple.c           is the C driver
9liblammpsplugin.c  is the LAMMPS library plugin loader
10
11You can then build the driver executable codes with a compile line
12like below.
13
14mpicc -c -O -Wall -g -I$HOME/lammps/src liblammpsplugin.c
15mpicc -c -O -Wall -g simple.c
16mpicc simple.o liblammpsplugin.o -ldl -o simpleC
17
18You also need to build LAMMPS as a shared library
19(see examples/COUPLE/README), e.g.
20
21cd $HOME/lammps/src
22make mode=shlib mpi
23
24or
25
26cd $HOME/lammps
27mkdir build-shared
28cd build-shared
29cmake -D BUILD_LIB=on -D BUILD_SHARED_LIBS=on ../cmake
30make
31
32You then run simpleC on a parallel machine
33on some number of processors Q with 3 arguments:
34
35% mpirun -np Q simpleC P in.lj $HOME/lammps/src/liblammps.so
36
37or
38
39% mpirun -np Q simpleC P in.lj $HOME/lammps/build-shared/liblammps.so
40
41P is the number of procs you want LAMMPS to run on (must be <= Q) and
42in.lj is a LAMMPS input script and the last argument is the path to
43the LAMMPS shared library. This either has to be an absolute path, or
44liblammps.so has to be in a folder that is included in the environment
45variable LD_LIBRARY_PATH so it will be found by the dynamic object loader.
46
47The driver will launch LAMMPS on P procs, read the input script a line
48at a time, and pass each command line to LAMMPS.  The final line of
49the script is a "run" command, so LAMMPS will run the problem.
50
51The driver then requests all the atom coordinates from LAMMPS, moves
52one of the atoms a small amount "epsilon", passes the coordinates back
53to LAMMPS, and runs LAMMPS again.  If you look at the output, you
54should see a small energy change between runs, due to the moved atom.
55
56The C driver is calling C-style routines in the src/library.cpp file
57of LAMMPS through the function pointers in the liblammpsplugin_t struct.
58This has the benefit that your binary is not linked to liblammps.so directly
59and thus you can change the name of the shared library (e.g. to have
60different variants compiled, or to load a different LAMMPS versions without
61having to update your executable). The shared library still has to be
62compatible with the compilation settings the plugin code.
63
64