From 21ff4407ab5e01d1f3d2f4c99c844ed7e47452cf Mon Sep 17 00:00:00 2001
From: Steven J Plimpton <sjplimp@singsing.sandia.gov>
Date: Tue, 16 Jan 2018 10:48:38 -0700
Subject: [PATCH] update of COUPLE/simple examples

---
 examples/COUPLE/simple/README     | 41 +++++++++++++++++--------------
 examples/COUPLE/simple/simple.c   |  2 +-
 examples/COUPLE/simple/simple.cpp | 17 +++++++------
 examples/COUPLE/simple/simple.f90 |  9 ++++---
 src/create_bonds.cpp              |  6 +++--
 src/delete_atoms.cpp              |  6 +++--
 src/fix_neigh_history.cpp         |  3 ++-
 7 files changed, 48 insertions(+), 36 deletions(-)

diff --git a/examples/COUPLE/simple/README b/examples/COUPLE/simple/README
index 404bb37004..8a97137bf7 100644
--- a/examples/COUPLE/simple/README
+++ b/examples/COUPLE/simple/README
@@ -17,33 +17,36 @@ additional wrapper library that interfaces the C interface of the
 LAMMPS library to Fortran and also translates the MPI communicator
 from Fortran to C.
 
-Once you have built LAMMPS as a library (see examples/COUPLE/README),
-you can then build any of the driver codes with compile lines like
-these, which include paths to the LAMMPS library interface, MPI (an
-installed MPICH in this case), and FFTW (assuming you built LAMMPS as
-a library with its PPPM solver).
+First build LAMMPS as a library (see examples/COUPLE/README), e.g. 
 
-This builds the C++ driver with the LAMMPS library using a C++ compiler:
+make mode=shlib mpi
 
-g++ -I/home/sjplimp/lammps/src -c simple.cpp
-g++ -L/home/sjplimp/lammps/src simple.o \
-    -llammps -lfftw -lmpich -lmpl -lpthread -o simpleCC
+You can then build any of the driver codes with compile lines like
+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 a C compiler:
+This builds the C++ driver with the LAMMPS library using the mpiCC
+(C++) compiler:
 
-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
+mpiCC -I/home/sjplimp/lammps/src -c simple.cpp
+mpiCC -L/home/sjplimp/lammps/src simple.o -llammps -lfftw -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
 
 This builds the Fortran wrapper and driver with the LAMMPS library
-using a Fortran and C compiler, using the wrapper in the fortran
-directory:
+using the mpicc (C) and mpifort (Fortran) compilers, using the wrapper
+in the fortran directory:
 
 cp ../fortran/libfwrapper.c .
-gcc -I/home/sjplimp/lammps/src -c libfwrapper.c
-gfortran -I/home/sjplimp/lammps/src -c simple.f90
-gfortran -L/home/sjplimp/lammps/src simple.o libfwrapper.o \
-    -llammps -lfftw -lfmpich -lmpich -lpthread -lstdc++ -o simpleF
+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
 
 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 cc813d78fe..ad603e09a6 100644
--- a/examples/COUPLE/simple/simple.c
+++ b/examples/COUPLE/simple/simple.c
@@ -145,7 +145,7 @@ int main(int narg, char **arg)
     for (i = 0; i < natoms; i++) type[i] = 1;
 
     lammps_command(lmp,"delete_atoms group all");
-    lammps_create_atoms(lmp,natoms,NULL,type,x,v);
+    lammps_create_atoms(lmp,natoms,NULL,type,x,v,NULL,0);
     lammps_command(lmp,"run 10");
   }
 
diff --git a/examples/COUPLE/simple/simple.cpp b/examples/COUPLE/simple/simple.cpp
index 894c708978..912f4b8689 100644
--- a/examples/COUPLE/simple/simple.cpp
+++ b/examples/COUPLE/simple/simple.cpp
@@ -109,11 +109,11 @@ int main(int narg, char **arg)
     int natoms = static_cast<int> (lmp->atom->natoms);
     x = new double[3*natoms];
     v = new double[3*natoms];
-    lammps_gather_atoms(lmp,"x",1,3,x);
-    lammps_gather_atoms(lmp,"v",1,3,v);
+    lammps_gather_atoms(lmp,(char *) "x",1,3,x);
+    lammps_gather_atoms(lmp,(char *) "v",1,3,v);
     double epsilon = 0.1;
     x[0] += epsilon;
-    lammps_scatter_atoms(lmp,"x",1,3,x);
+    lammps_scatter_atoms(lmp,(char *) "x",1,3,x);
 
     // these 2 lines are the same
 
@@ -124,21 +124,22 @@ int main(int narg, char **arg)
   // extract force on single atom two different ways
 
   if (lammps == 1) {
-    double **f = (double **) lammps_extract_atom(lmp,"f");
+    double **f = (double **) lammps_extract_atom(lmp,(char *) "f");
     printf("Force on 1 atom via extract_atom: %g\n",f[0][0]);
 
-    double *fx = (double *) lammps_extract_variable(lmp,"fx","all");
+    double *fx = (double *) 
+      lammps_extract_variable(lmp,(char *) "fx",(char *) "all");
     printf("Force on 1 atom via extract_variable: %g\n",fx[0]);
   }
 
   // use commands_string() and commands_list() to invoke more commands
 
-  char *strtwo = "run 10\nrun 20";
+  char *strtwo = (char *) "run 10\nrun 20";
   if (lammps == 1) lammps_commands_string(lmp,strtwo);
 
   char *cmds[2];
-  cmds[0] = "run 10";
-  cmds[1] = "run 20";
+  cmds[0] = (char *) "run 10";
+  cmds[1] = (char *) "run 20";
   if (lammps == 1) lammps_commands_list(lmp,2,cmds);
 
   // delete all atoms
diff --git a/examples/COUPLE/simple/simple.f90 b/examples/COUPLE/simple/simple.f90
index eb5c272527..0ac3e4fd5c 100644
--- a/examples/COUPLE/simple/simple.f90
+++ b/examples/COUPLE/simple/simple.f90
@@ -115,9 +115,12 @@ PROGRAM f_driver
      CALL lammps_get_natoms(ptr,natoms)
      ALLOCATE(x(3*natoms))
 
-     CALL lammps_gather_atoms(ptr,'x',1,3,x);
-     x(1) = x(1) + epsilon
-     CALL lammps_scatter_atoms(ptr,'x',1,3,x);
+     ! 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);
+     !x(1) = x(1) + epsilon
+     !CALL lammps_scatter_atoms(ptr,'x',1,3,x);
 
      DEALLOCATE(x)
 
diff --git a/src/create_bonds.cpp b/src/create_bonds.cpp
index ff62e86787..16c332e3a5 100644
--- a/src/create_bonds.cpp
+++ b/src/create_bonds.cpp
@@ -306,9 +306,11 @@ void CreateBonds::many()
               nadd_bonds,atom->nbonds);
     }
   }
+
   // trigger clearing the list of available neighbor list requests
-  // and a full rebuild of them during the next run setup.
-  // otherwise the request from this command may linger around.
+  // and a full rebuild of them during the next run setup
+  // otherwise the request from this command may linger around
+
   neighbor->init();
 }
 
diff --git a/src/delete_atoms.cpp b/src/delete_atoms.cpp
index a4219dbecb..cbce351ea8 100644
--- a/src/delete_atoms.cpp
+++ b/src/delete_atoms.cpp
@@ -407,9 +407,11 @@ void DeleteAtoms::delete_overlap(int narg, char **arg)
       break;
     }
   }
+
   // trigger clearing the list of available neighbor list requests
-  // and a full rebuild of them during the next run setup.
-  // otherwise the request from this command may linger around.
+  // and a full rebuild of them during the next run setup
+  // otherwise the request from this command may linger around
+
   neighbor->init();
 }
 
diff --git a/src/fix_neigh_history.cpp b/src/fix_neigh_history.cpp
index 623fbff756..e8bfe840d8 100644
--- a/src/fix_neigh_history.cpp
+++ b/src/fix_neigh_history.cpp
@@ -715,12 +715,13 @@ void FixNeighHistory::set_arrays(int i)
 int FixNeighHistory::pack_reverse_comm_size(int n, int first)
 {
   int i,last;
+  int dnump1 = dnum + 1;
 
   int m = 0;
   last = first + n;
 
   for (i = first; i < last; i++)
-    m += 1 + (dnum+1)*npartner[i];
+    m += 1 + dnump1*npartner[i];
 
   return m;
 }
-- 
GitLab