git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@14073 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp 2015-09-24 22:48:45 +00:00
parent d2a2124b56
commit 663551ee9f
4 changed files with 95904 additions and 0 deletions

View File

@ -0,0 +1,35 @@
This directory has a C++ code multiple.cpp which illustrates how a
driver code can create multiple instantiations of LAMMPS to run
independent simulations simultaneously, on a set of processors
allocated by MPI.
Once you have built LAMMPS as a library (see examples/COUPLE/README),
you can then build 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).
g++ -I/home/sjplimp/lammps/src -c multiple.cpp
g++ -L/home/sjplimp/lammps/src multiple.o \
-llammps -lfftw -lmpich -lmpl -lpthread -o multiple
If you then run this command:
% mpirun -np 8 multiple 4 in.chain 1.0 0.5
you will create 4 instances of LAMMPS, each running on 2 of the
allocated 8 processors. The final two arguments are the base
temperature and a delta temperature added by each instance. The
provided input script in.chain uses those temperatures, set as a
variable "t" when each instance of LAMMPS is created.
After a few seconds you should get this output to the screen:
Instance 1, final temp = 1.00469
Instance 2, final temp = 1.50395
Instance 3, final temp = 1.99873
Instance 4, final temp = 2.50862
indicating the runs equilibrated to 4 temperatures separated by 0.5
(in LJ units). There should also be 4 screen files (screen.N) and 4
log files (log.lammps.N) from the individual LAMMPS runs.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,25 @@
# FENE beadspring benchmark
units lj
atom_style bond
special_bonds fene
read_data data.chain
neighbor 0.4 bin
neigh_modify every 1 delay 1
bond_style fene
bond_coeff 1 30.0 1.5 1.0 1.0
pair_style lj/cut 1.12
pair_modify shift yes
pair_coeff 1 1 1.0 1.0 1.12
fix 1 all nve
fix 2 all langevin $t $t 1.0 904297
thermo 100
timestep 0.012
run 500

View File

@ -0,0 +1,134 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
www.cs.sandia.gov/~sjplimp/lammps.html
Steve Plimpton, sjplimp@sandia.gov, Sandia National Laboratories
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
// example of how a calling program can invoke
// multiple instances of LAMMPS, each on a subset of procs,
// and have each of them perform a different run, and collect output info
// Syntax: mpirun -np P multiple N in.lammps T Tdelta
// P = # of total procs to run the driver program on
// N = # of instances of LAMMPS to create, P must be divisible by N
// in.lammps = LAMMPS input script,
// which takes "t" as a temperature variable
// T = baseline temperature
// Tdelta = incremental temperature for each of N runs
// See README for compilation instructions
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "mpi.h"
#include "lammps.h" // these are LAMMPS include files
#include "input.h"
#include "atom.h"
#include "library.h"
using namespace LAMMPS_NS;
int main(int narg, char **arg)
{
// setup MPI and various communicators
// driver runs on all procs in MPI_COMM_WORLD
// comm_lammps only has 1st P procs (could be all or any subset)
MPI_Init(&narg,&arg);
if (narg != 5) {
printf("Syntax: multiple N in.lammps T Tdelta\n");
exit(1);
}
int me,nprocs;
MPI_Comm_rank(MPI_COMM_WORLD,&me);
MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
int ninstance = atoi(arg[1]);
if (nprocs % ninstance) {
if (me == 0)
printf("ERROR: Total procs must be divisble by N\n");
MPI_Abort(MPI_COMM_WORLD,1);
}
char *infile = arg[2];
double temperature = atof(arg[3]);
double tdelta = atof(arg[4]);
// create one communicator per instancem each with P/N procs
int instance = me*ninstance / nprocs;
MPI_Comm comm_lammps;
MPI_Comm_split(MPI_COMM_WORLD,instance,0,&comm_lammps);
// each instance: unique screen file, log file, temperature
char str1[32],str2[32],str3[32];
char **lmparg = new char*[8];
lmparg[0] = NULL; // required placeholder for program name
lmparg[1] = (char *) "-screen";
sprintf(str1,"screen.%d",instance);
lmparg[2] = str1;
lmparg[3] = (char *) "-log";
sprintf(str2,"log.lammps.%d",instance);
lmparg[4] = str2;
lmparg[5] = (char *) "-var";
lmparg[6] = (char *) "t";
sprintf(str3,"%g",temperature + instance*tdelta);
lmparg[7] = str3;
// open N instances of LAMMPS
// either of these methods will work
LAMMPS *lmp = new LAMMPS(8,lmparg,comm_lammps);
//LAMMPS *lmp;
//lammps_open(8,lmparg,comm_lammps,(void **) &lmp);
delete [] lmparg;
// run input script thru all instances of LAMMPS
lammps_file(lmp,infile);
// query final temperature and print result for each instance
double *ptr = (double *)
lammps_extract_compute(lmp,(char *) "thermo_temp",0,0);
double finaltemp = *ptr;
double *temps = new double[ninstance];
for (int i = 0; i < ninstance; i++) temps[i] = 0.0;
int me_lammps;
MPI_Comm_rank(comm_lammps,&me_lammps);
if (me_lammps == 0) temps[instance] = finaltemp;
double *alltemps = new double[ninstance];
MPI_Allreduce(temps,alltemps,ninstance,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD);
if (me == 0)
for (int i = 0; i < ninstance; i++)
printf("Instance %d, final temp = %g\n",i+1,alltemps[i]);
delete [] temps;
delete [] alltemps;
// delete LAMMPS instances
delete lmp;
// close down MPI
MPI_Comm_free(&comm_lammps);
MPI_Finalize();
}