diff --git a/examples/COUPLE/.gitignore b/examples/COUPLE/.gitignore index 6ffb58df7d..a3927e0c93 100644 --- a/examples/COUPLE/.gitignore +++ b/examples/COUPLE/.gitignore @@ -2,3 +2,7 @@ *.d *.a *~ +liblammps.mod +simpleC +simpleCC +simpleF diff --git a/examples/COUPLE/simple/README b/examples/COUPLE/simple/README index 8a97137bf7..8b195431f7 100644 --- a/examples/COUPLE/simple/README +++ b/examples/COUPLE/simple/README @@ -8,16 +8,15 @@ code to perform a coupled calculation. simple.cpp is the C++ driver simple.c is the C driver simple.f90 is the Fortran driver -libfwrapper.c is the Fortran-to-C wrapper The 3 codes do the same thing, so you can compare them to see how to -drive LAMMPS from each language. See lammps/python/example/simple.py +drive LAMMPS from each language. See python/example/simple.py to do something similar from Python. The Fortran driver requires an additional wrapper library that interfaces the C interface of the LAMMPS library to Fortran and also translates the MPI communicator from Fortran to C. -First build LAMMPS as a library (see examples/COUPLE/README), e.g. +First build LAMMPS as a library (see examples/COUPLE/README), e.g. make mode=shlib mpi @@ -26,27 +25,23 @@ these, which include paths to the LAMMPS library interface, and linking with FFTW (only needed if you built LAMMPS as a library with its PPPM solver). -This builds the C++ driver with the LAMMPS library using the mpiCC +This builds the C++ driver with the LAMMPS library using the mpicxx (C++) compiler: -mpiCC -I/home/sjplimp/lammps/src -c simple.cpp -mpiCC -L/home/sjplimp/lammps/src simple.o -llammps -lfftw -o simpleCC +mpicxx -I/home/sjplimp/lammps/src -c simple.cpp +mpicxx -L/home/sjplimp/lammps/src simple.o -llammps -o simpleCC This builds the C driver with the LAMMPS library using the mpicc (C) compiler: mpicc -I/home/sjplimp/lammps/src -c simple.c -mpicc -L/home/sjplimp/lammps/src simple.o -llammps -lfftw -o simpleC +mpicc -L/home/sjplimp/lammps/src simple.o -llammps -o simpleC -This builds the Fortran wrapper and driver with the LAMMPS library -using the mpicc (C) and mpifort (Fortran) compilers, using the wrapper -in the fortran directory: +This builds the Fortran module and driver with the LAMMPS library +using the mpifort (Fortran) compilers, using the Fortran module from +the fortran directory: -cp ../fortran/libfwrapper.c . -mpicc -I/home/sjplimp/lammps/src -c libfwrapper.c -mpifort -c simple.f90 -mpifort -L/home/sjplimp/lammps/src simple.o libfwrapper.o \ - -llammps -lfftw -o simpleF +mpifort -L/home/sjplimp/lammps/src ../../../fortran/lammps.f90 simple.f90 -llammps -o simpleF You then run simpleCC, simpleC, or simpleF on a parallel machine on some number of processors Q with 2 arguments: diff --git a/examples/COUPLE/simple/simple.c b/examples/COUPLE/simple/simple.c index aceaa63bc8..a5ce281b1d 100644 --- a/examples/COUPLE/simple/simple.c +++ b/examples/COUPLE/simple/simple.c @@ -23,7 +23,7 @@ #include #include #include -#include "lammps/library.h" /* this is a LAMMPS include file */ +#include "library.h" /* this is a LAMMPS include file */ int main(int narg, char **arg) { @@ -124,10 +124,10 @@ int main(int narg, char **arg) /* use commands_string() and commands_list() to invoke more commands */ - char *strtwo = "run 10\nrun 20"; + const char *strtwo = "run 10\nrun 20"; if (lammps == 1) lammps_commands_string(lmp,strtwo); - char *cmds[2]; + const char *cmds[2]; cmds[0] = "run 10"; cmds[1] = "run 20"; if (lammps == 1) lammps_commands_list(lmp,2,cmds); diff --git a/examples/COUPLE/simple/simple.cpp b/examples/COUPLE/simple/simple.cpp index a76ed8a6e9..8660dfa656 100644 --- a/examples/COUPLE/simple/simple.cpp +++ b/examples/COUPLE/simple/simple.cpp @@ -25,10 +25,10 @@ #include // these are LAMMPS include files -#include -#include -#include -#include +#include "lammps.h" +#include "input.h" +#include "atom.h" +#include "library.h" using namespace LAMMPS_NS; @@ -135,10 +135,10 @@ int main(int narg, char **arg) // use commands_string() and commands_list() to invoke more commands - char *strtwo = (char *) "run 10\nrun 20"; + const char *strtwo = (char *) "run 10\nrun 20"; if (lammps == 1) lammps_commands_string(lmp,strtwo); - char *cmds[2]; + const char *cmds[2]; cmds[0] = (char *) "run 10"; cmds[1] = (char *) "run 20"; if (lammps == 1) lammps_commands_list(lmp,2,cmds); diff --git a/examples/COUPLE/simple/simple.f90 b/examples/COUPLE/simple/simple.f90 index 0ac3e4fd5c..aacbbfcb79 100644 --- a/examples/COUPLE/simple/simple.f90 +++ b/examples/COUPLE/simple/simple.f90 @@ -18,13 +18,14 @@ ! See README for compilation instructions PROGRAM f_driver + USE mpi + USE liblammps IMPLICIT NONE - INCLUDE 'mpif.h' INTEGER, PARAMETER :: fp=20 INTEGER :: n, narg, ierr, me, nprocs, natoms - INTEGER :: lammps, nprocs_lammps, comm_lammps - INTEGER (kind=8) :: ptr + INTEGER :: color, nprocs_lammps, comm_lammps + TYPE(LAMMPS) :: lmp REAL (kind=8), ALLOCATABLE :: x(:) REAL (kind=8), PARAMETER :: epsilon=0.1 @@ -58,14 +59,14 @@ PROGRAM f_driver END IF END IF - lammps = 0 + color = 0 IF (me < nprocs_lammps) THEN - lammps = 1 + color = 1 ELSE - lammps = MPI_UNDEFINED + color = MPI_UNDEFINED END IF - CALL mpi_comm_split(MPI_COMM_WORLD,lammps,0,comm_lammps,ierr) + CALL mpi_comm_split(MPI_COMM_WORLD,color,0,comm_lammps,ierr) ! open LAMMPS input script on rank zero @@ -81,7 +82,7 @@ PROGRAM f_driver ! (could just send it to proc 0 of comm_lammps and let it Bcast) ! all LAMMPS procs call lammps_command() on the line */ - IF (lammps == 1) CALL lammps_open(comm_lammps,ptr) + IF (color == 1) lmp=lammps(comm=comm_lammps) n = 0 DO @@ -99,7 +100,7 @@ PROGRAM f_driver CALL mpi_bcast(n,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr) IF (n == 0) EXIT CALL mpi_bcast(line,n,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr) - IF (lammps == 1) CALL lammps_command(ptr,line,n) + IF (color == 1) CALL lmp%command(line(1:n)) END DO CLOSE(UNIT=fp) @@ -109,27 +110,27 @@ PROGRAM f_driver ! put coords back into LAMMPS ! run a single step with changed coords */ - IF (lammps == 1) THEN - CALL lammps_command(ptr,'run 10',6) + IF (color == 1) THEN + CALL lmp%command('run 10') - CALL lammps_get_natoms(ptr,natoms) + natoms = NINT(lmp%get_natoms()) ALLOCATE(x(3*natoms)) ! these calls are commented out, b/c libfwrapper.c ! needs to be updated to use gather_atoms and scatter_atoms - !CALL lammps_gather_atoms(ptr,'x',1,3,x); + !CALL lammps_gather_atoms(ptr,'x',1,3,x) !x(1) = x(1) + epsilon - !CALL lammps_scatter_atoms(ptr,'x',1,3,x); + !CALL lammps_scatter_atoms(ptr,'x',1,3,x) DEALLOCATE(x) - CALL lammps_command(ptr,'run 1',5); + CALL lmp%command('run 1') END IF ! free LAMMPS object - IF (lammps == 1) CALL lammps_close(ptr); + IF (color == 1) CALL lmp%close() ! close down MPI