From 140cdf94854f5830a706ca52a096208260e83619 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 7 Jan 2011 21:42:19 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@5504 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/ASPHERE/atom_vec_ellipsoid.cpp | 3 ++ src/COLLOID/atom_vec_colloid.cpp | 3 ++ src/DIPOLE/atom_vec_dipole.cpp | 3 ++ src/GRANULAR/atom_vec_granular.cpp | 3 ++ src/GRANULAR/fix_pour.cpp | 16 ++++---- src/MOLECULE/atom_vec_angle.cpp | 3 ++ src/MOLECULE/atom_vec_bond.cpp | 3 ++ src/MOLECULE/atom_vec_full.cpp | 3 ++ src/MOLECULE/atom_vec_molecular.cpp | 3 ++ src/PERI/atom_vec_peri.cpp | 5 ++- src/PERI/fix_peri_neigh.cpp | 4 +- src/REPLICA/prd.cpp | 9 +++-- src/REPLICA/tad.cpp | 9 +++-- src/SRD/fix_srd.cpp | 6 ++- src/USER-EFF/Install.sh | 4 +- src/USER-EFF/atom_vec_electron.cpp | 9 +++-- src/USER-IMD/fix_imd.cpp | 6 +-- src/XTC/dump_xtc.cpp | 11 +++--- src/XTC/dump_xtc.h | 2 +- src/atom_vec_atomic.cpp | 3 ++ src/atom_vec_charge.cpp | 3 ++ src/atom_vec_hybrid.cpp | 3 ++ src/create_atoms.cpp | 8 +++- src/delete_atoms.cpp | 9 +++-- src/delete_bonds.cpp | 56 +++++++++++++-------------- src/displace_atoms.cpp | 7 ++-- src/displace_box.cpp | 7 ++-- src/dump.cpp | 10 +++-- src/dump.h | 5 ++- src/dump_atom.cpp | 18 ++++----- src/dump_atom.h | 12 +++--- src/dump_cfg.cpp | 6 ++- src/dump_cfg.h | 2 +- src/dump_custom.cpp | 18 ++++----- src/dump_custom.h | 12 +++--- src/dump_dcd.cpp | 8 ++-- src/dump_dcd.h | 2 +- src/dump_local.cpp | 4 +- src/dump_local.h | 2 +- src/dump_xyz.cpp | 4 +- src/dump_xyz.h | 2 +- src/finish.cpp | 13 +++---- src/fix_deposit.cpp | 21 +++++----- src/fix_orient_fcc.cpp | 15 ++++---- src/lammps.cpp | 17 +++++--- src/lmptype.h | 58 ++++++++++++++++++++++++++-- src/read_data.cpp | 60 +++++++++++++++++++++-------- src/read_restart.cpp | 52 +++++++++++++++++++------ src/replicate.cpp | 56 ++++++++++++++++----------- src/thermo.cpp | 27 +++++++++---- src/thermo.h | 2 +- src/write_restart.cpp | 10 ++++- 52 files changed, 417 insertions(+), 220 deletions(-) diff --git a/src/ASPHERE/atom_vec_ellipsoid.cpp b/src/ASPHERE/atom_vec_ellipsoid.cpp index ddf95831af..e48e7ae303 100755 --- a/src/ASPHERE/atom_vec_ellipsoid.cpp +++ b/src/ASPHERE/atom_vec_ellipsoid.cpp @@ -17,6 +17,7 @@ #include "stdlib.h" #include "atom_vec_ellipsoid.h" +#include "lmptype.h" #include "math_extra.h" #include "atom.h" #include "force.h" @@ -62,6 +63,8 @@ void AtomVecEllipsoid::grow(int n) if (n == 0) nmax += DELTA; else nmax = n; atom->nmax = nmax; + if (nmax < 0 || nmax > MAXSMALLINT) + error->one("Per-processor system is too big"); tag = atom->tag = (int *) memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); diff --git a/src/COLLOID/atom_vec_colloid.cpp b/src/COLLOID/atom_vec_colloid.cpp index 3c13ecde0e..0ba21a7356 100644 --- a/src/COLLOID/atom_vec_colloid.cpp +++ b/src/COLLOID/atom_vec_colloid.cpp @@ -13,6 +13,7 @@ #include "stdlib.h" #include "atom_vec_colloid.h" +#include "lmptype.h" #include "atom.h" #include "force.h" #include "domain.h" @@ -58,6 +59,8 @@ void AtomVecColloid::grow(int n) if (n == 0) nmax += DELTA; else nmax = n; atom->nmax = nmax; + if (nmax < 0 || nmax > MAXSMALLINT) + error->one("Per-processor system is too big"); tag = atom->tag = (int *) memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); diff --git a/src/DIPOLE/atom_vec_dipole.cpp b/src/DIPOLE/atom_vec_dipole.cpp index f3935cccef..cc81711b4d 100644 --- a/src/DIPOLE/atom_vec_dipole.cpp +++ b/src/DIPOLE/atom_vec_dipole.cpp @@ -13,6 +13,7 @@ #include "stdlib.h" #include "atom_vec_dipole.h" +#include "lmptype.h" #include "atom.h" #include "domain.h" #include "modify.h" @@ -57,6 +58,8 @@ void AtomVecDipole::grow(int n) if (n == 0) nmax += DELTA; else nmax = n; atom->nmax = nmax; + if (nmax < 0 || nmax > MAXSMALLINT) + error->one("Per-processor system is too big"); tag = atom->tag = (int *) memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); diff --git a/src/GRANULAR/atom_vec_granular.cpp b/src/GRANULAR/atom_vec_granular.cpp index 0a37ae8e9a..0ebb38d8f2 100644 --- a/src/GRANULAR/atom_vec_granular.cpp +++ b/src/GRANULAR/atom_vec_granular.cpp @@ -15,6 +15,7 @@ #include "stdlib.h" #include "string.h" #include "atom_vec_granular.h" +#include "lmptype.h" #include "atom.h" #include "domain.h" #include "modify.h" @@ -80,6 +81,8 @@ void AtomVecGranular::grow(int n) if (n == 0) nmax += DELTA; else nmax = n; atom->nmax = nmax; + if (nmax < 0 || nmax > MAXSMALLINT) + error->one("Per-processor system is too big"); tag = atom->tag = (int *) memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); diff --git a/src/GRANULAR/fix_pour.cpp b/src/GRANULAR/fix_pour.cpp index 8b00fde01b..0f54bbf79b 100644 --- a/src/GRANULAR/fix_pour.cpp +++ b/src/GRANULAR/fix_pour.cpp @@ -484,18 +484,20 @@ void FixPour::pre_exchange() } } - // set tag # of new particles beyond all previous atoms // reset global natoms + // set tag # of new particles beyond all previous atoms // if global map exists, reset it now instead of waiting for comm // since deleting atoms messes up ghosts - if (atom->tag_enable) { - atom->tag_extend(); + if (nnear - nprevious > 0) { atom->natoms += nnear - nprevious; - if (atom->map_style) { - atom->nghost = 0; - atom->map_init(); - atom->map_set(); + if (atom->tag_enable) { + atom->tag_extend(); + if (atom->map_style) { + atom->nghost = 0; + atom->map_init(); + atom->map_set(); + } } } diff --git a/src/MOLECULE/atom_vec_angle.cpp b/src/MOLECULE/atom_vec_angle.cpp index 6789db5006..33390ee34d 100644 --- a/src/MOLECULE/atom_vec_angle.cpp +++ b/src/MOLECULE/atom_vec_angle.cpp @@ -13,6 +13,7 @@ #include "stdlib.h" #include "atom_vec_angle.h" +#include "lmptype.h" #include "atom.h" #include "domain.h" #include "modify.h" @@ -59,6 +60,8 @@ void AtomVecAngle::grow(int n) if (n == 0) nmax += DELTA; else nmax = n; atom->nmax = nmax; + if (nmax < 0 || nmax > MAXSMALLINT) + error->one("Per-processor system is too big"); tag = atom->tag = (int *) memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); diff --git a/src/MOLECULE/atom_vec_bond.cpp b/src/MOLECULE/atom_vec_bond.cpp index 1e8f913237..13ea1e5e2b 100644 --- a/src/MOLECULE/atom_vec_bond.cpp +++ b/src/MOLECULE/atom_vec_bond.cpp @@ -13,6 +13,7 @@ #include "stdlib.h" #include "atom_vec_bond.h" +#include "lmptype.h" #include "atom.h" #include "domain.h" #include "modify.h" @@ -59,6 +60,8 @@ void AtomVecBond::grow(int n) if (n == 0) nmax += DELTA; else nmax = n; atom->nmax = nmax; + if (nmax < 0 || nmax > MAXSMALLINT) + error->one("Per-processor system is too big"); tag = atom->tag = (int *) memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); diff --git a/src/MOLECULE/atom_vec_full.cpp b/src/MOLECULE/atom_vec_full.cpp index 5815256fcc..2d733ebf41 100644 --- a/src/MOLECULE/atom_vec_full.cpp +++ b/src/MOLECULE/atom_vec_full.cpp @@ -13,6 +13,7 @@ #include "stdlib.h" #include "atom_vec_full.h" +#include "lmptype.h" #include "atom.h" #include "domain.h" #include "modify.h" @@ -59,6 +60,8 @@ void AtomVecFull::grow(int n) if (n == 0) nmax += DELTA; else nmax = n; atom->nmax = nmax; + if (nmax < 0 || nmax > MAXSMALLINT) + error->one("Per-processor system is too big"); tag = atom->tag = (int *) memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); diff --git a/src/MOLECULE/atom_vec_molecular.cpp b/src/MOLECULE/atom_vec_molecular.cpp index 131e80c599..07c46724aa 100644 --- a/src/MOLECULE/atom_vec_molecular.cpp +++ b/src/MOLECULE/atom_vec_molecular.cpp @@ -13,6 +13,7 @@ #include "stdlib.h" #include "atom_vec_molecular.h" +#include "lmptype.h" #include "atom.h" #include "domain.h" #include "modify.h" @@ -59,6 +60,8 @@ void AtomVecMolecular::grow(int n) if (n == 0) nmax += DELTA; else nmax = n; atom->nmax = nmax; + if (nmax < 0 || nmax > MAXSMALLINT) + error->one("Per-processor system is too big"); tag = atom->tag = (int *) memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); diff --git a/src/PERI/atom_vec_peri.cpp b/src/PERI/atom_vec_peri.cpp index 4e43d7a6bb..d20809e6bd 100644 --- a/src/PERI/atom_vec_peri.cpp +++ b/src/PERI/atom_vec_peri.cpp @@ -18,6 +18,7 @@ #include "float.h" #include "stdlib.h" #include "atom_vec_peri.h" +#include "lmptype.h" #include "atom.h" #include "domain.h" #include "modify.h" @@ -60,7 +61,9 @@ void AtomVecPeri::grow(int n) if (n == 0) nmax += DELTA; else nmax = n; atom->nmax = nmax; - + if (nmax < 0 || nmax > MAXSMALLINT) + error->one("Per-processor system is too big"); + tag = atom->tag = (int *) memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); type = atom->type = (int *) diff --git a/src/PERI/fix_peri_neigh.cpp b/src/PERI/fix_peri_neigh.cpp index 14dbf8cbba..d56946caab 100644 --- a/src/PERI/fix_peri_neigh.cpp +++ b/src/PERI/fix_peri_neigh.cpp @@ -300,12 +300,12 @@ void FixPeriNeigh::setup(int vflag) if (screen) { fprintf(screen,"Peridynamic bonds:\n"); fprintf(screen," total # of bonds = %d\n",nall); - fprintf(screen," bonds/atom = %g\n",nall/atom->natoms); + fprintf(screen," bonds/atom = %g\n",(double)nall/atom->natoms); } if (logfile) { fprintf(logfile,"Peridynamic bonds:\n"); fprintf(logfile," total # of bonds = %d\n",nall); - fprintf(logfile," bonds/atom = %g\n",nall/atom->natoms); + fprintf(logfile," bonds/atom = %g\n",(double)nall/atom->natoms); } } } diff --git a/src/REPLICA/prd.cpp b/src/REPLICA/prd.cpp index 14686f91ac..eb28310ffb 100644 --- a/src/REPLICA/prd.cpp +++ b/src/REPLICA/prd.cpp @@ -376,13 +376,14 @@ void PRD::command(int narg, char **arg) neighbor->ndanger = ndanger; if (me_universe == 0) { + char str[128]; + sprintf(str,"Loop time of %%g on %%d procs for %%d steps with %s atoms\n", + BIGINT_FORMAT); if (universe->uscreen) - fprintf(universe->uscreen, - "Loop time of %g on %d procs for %d steps with %lu atoms\n", + fprintf(universe->uscreen,str, timer->array[TIME_LOOP],nprocs_universe,nsteps,atom->natoms); if (universe->ulogfile) - fprintf(universe->ulogfile, - "Loop time of %g on %d procs for %d steps with %lu atoms\n", + fprintf(universe->ulogfile,str, timer->array[TIME_LOOP],nprocs_universe,nsteps,atom->natoms); } diff --git a/src/REPLICA/tad.cpp b/src/REPLICA/tad.cpp index 459b0707a8..6948dec0d1 100644 --- a/src/REPLICA/tad.cpp +++ b/src/REPLICA/tad.cpp @@ -385,13 +385,14 @@ void TAD::command(int narg, char **arg) neighbor->ndanger = ndanger; if (me_universe == 0) { + char str[128]; + sprintf(str,"Loop time of %%g on %%d procs for %%d steps with %s atoms\n", + BIGINT_FORMAT); if (universe->uscreen) - fprintf(universe->uscreen, - "Loop time of %g on %d procs for %d steps with %lu atoms\n", + fprintf(universe->uscreen,str, timer->array[TIME_LOOP],nprocs_universe,nsteps,atom->natoms); if (universe->ulogfile) - fprintf(universe->ulogfile, - "Loop time of %g on %d procs for %d steps with %lu atoms\n", + fprintf(universe->ulogfile,str, timer->array[TIME_LOOP],nprocs_universe,nsteps,atom->natoms); } diff --git a/src/SRD/fix_srd.cpp b/src/SRD/fix_srd.cpp index a59d105996..ae867aaf68 100644 --- a/src/SRD/fix_srd.cpp +++ b/src/SRD/fix_srd.cpp @@ -2315,9 +2315,11 @@ void FixSRD::parameterize() // print SRD parameters if (me == 0) { + char str[64]; + sprintf(str," SRD/big particles = %s %s\n",BIGINT_FORMAT,BIGINT_FORMAT); if (screen) { fprintf(screen,"SRD info:\n"); - fprintf(screen," SRD/big particles = %lu %lu\n",nsrd,mbig); + fprintf(screen,str,nsrd,mbig); fprintf(screen," big particle diameter max/min = %g %g\n", maxbigdiam,minbigdiam); fprintf(screen," SRD temperature & lamda = %g %g\n", @@ -2332,7 +2334,7 @@ void FixSRD::parameterize() } if (logfile) { fprintf(logfile,"SRD info:\n"); - fprintf(logfile," SRD/big particles = %lu %lu\n",nsrd,mbig); + fprintf(logfile,str,nsrd,mbig); fprintf(logfile," big particle diameter max/min = %g %g\n", maxbigdiam,minbigdiam); fprintf(logfile," SRD temperature & lamda = %g %g\n", diff --git a/src/USER-EFF/Install.sh b/src/USER-EFF/Install.sh index 407168c564..64a7b71c0b 100644 --- a/src/USER-EFF/Install.sh +++ b/src/USER-EFF/Install.sh @@ -44,7 +44,7 @@ elif (test $1 = 0) then rm ../compute_temp_deform_eff.cpp rm ../compute_temp_eff.cpp rm ../compute_temp_region_eff.cpp - rm ../fix_langevin_eff.cpp .. + rm ../fix_langevin_eff.cpp rm ../fix_nh_eff.cpp rm ../fix_nve_eff.cpp rm ../fix_nvt_eff.cpp @@ -61,7 +61,7 @@ elif (test $1 = 0) then rm ../compute_temp_deform_eff.h rm ../compute_temp_eff.h rm ../compute_temp_region_eff.h - rm ../fix_langevin_eff.h .. + rm ../fix_langevin_eff.h rm ../fix_nh_eff.h rm ../fix_nve_eff.h rm ../fix_nvt_eff.h diff --git a/src/USER-EFF/atom_vec_electron.cpp b/src/USER-EFF/atom_vec_electron.cpp index f3a3997684..ceba59846b 100644 --- a/src/USER-EFF/atom_vec_electron.cpp +++ b/src/USER-EFF/atom_vec_electron.cpp @@ -15,9 +15,9 @@ Contributing author: Andres Jaramillo-Botero (Caltech) ------------------------------------------------------------------------- */ -#include "math.h" #include "stdlib.h" #include "atom_vec_electron.h" +#include "lmptype.h" #include "atom.h" #include "domain.h" #include "modify.h" @@ -63,7 +63,9 @@ void AtomVecElectron::grow(int n) if (n == 0) nmax += DELTA; else nmax = n; atom->nmax = nmax; - + if (nmax < 0 || nmax > MAXSMALLINT) + error->one("Per-processor system is too big"); + tag = atom->tag = (int *) memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); type = atom->type = (int *) @@ -102,7 +104,8 @@ void AtomVecElectron::grow_reset() tag = atom->tag; type = atom->type; mask = atom->mask; image = atom->image; x = atom->x; v = atom->v; f = atom->f; - q = atom->q; eradius = atom->eradius; ervel = atom->ervel; erforce = atom->erforce; + q = atom->q; + eradius = atom->eradius; ervel = atom->ervel; erforce = atom->erforce; } /* ---------------------------------------------------------------------- */ diff --git a/src/USER-IMD/fix_imd.cpp b/src/USER-IMD/fix_imd.cpp index 427d6ed496..380f67cc24 100644 --- a/src/USER-IMD/fix_imd.cpp +++ b/src/USER-IMD/fix_imd.cpp @@ -268,10 +268,8 @@ FixIMD::FixIMD(LAMMPS *lmp, int narg, char **arg) : if (imd_trate < 1) error->all("Illegal fix imd parameter. trate < 1."); - bigint n; - if (igroup == group->find("all")) n = atom->natoms; - else n = group->count(igroup); - if (n > MAXINT32) error->all("Too many atoms for fix imd"); + bigint n = group->count(igroup); + if (n > MAXSMALLINT) error->all("Too many atoms for fix imd"); num_coords = static_cast (n); MPI_Comm_rank(world,&me); diff --git a/src/XTC/dump_xtc.cpp b/src/XTC/dump_xtc.cpp index 32d6f3cf3c..8dadedc465 100644 --- a/src/XTC/dump_xtc.cpp +++ b/src/XTC/dump_xtc.cpp @@ -67,11 +67,9 @@ DumpXTC::DumpXTC(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg) // allocate global array for atom coords - bigint n; - if (igroup == 0) n = static_cast (atom->natoms); - else n = static_cast (group->count(igroup)); + bigint n = group->count(igroup); if (n > MAXSMALLINT) error->all("Too many atoms for dump xtc"); - natoms = n; + natoms = static_cast (n); coords = (float *) memory->smalloc(3*natoms*sizeof(float),"dump:coords"); @@ -136,8 +134,11 @@ void DumpXTC::openfile() /* ---------------------------------------------------------------------- */ -void DumpXTC::write_header(int n) +void DumpXTC::write_header(bigint nbig) { + if (nbig > MAXSMALLINT) error->all("Too many atoms for dump xtc"); + int n = nbig; + // all procs realloc coords if total count grew if (n != natoms) { diff --git a/src/XTC/dump_xtc.h b/src/XTC/dump_xtc.h index ebc928cc15..e1e2ca0254 100644 --- a/src/XTC/dump_xtc.h +++ b/src/XTC/dump_xtc.h @@ -48,7 +48,7 @@ class DumpXTC : public Dump { void init_style(); int modify_param(int, char **); void openfile(); - void write_header(int); + void write_header(bigint); int count(); void pack(int *); void write_data(int, double *); diff --git a/src/atom_vec_atomic.cpp b/src/atom_vec_atomic.cpp index 665f66f041..13dd6b4a9b 100644 --- a/src/atom_vec_atomic.cpp +++ b/src/atom_vec_atomic.cpp @@ -13,6 +13,7 @@ #include "stdlib.h" #include "atom_vec_atomic.h" +#include "lmptype.h" #include "atom.h" #include "domain.h" #include "modify.h" @@ -53,6 +54,8 @@ void AtomVecAtomic::grow(int n) if (n == 0) nmax += DELTA; else nmax = n; atom->nmax = nmax; + if (nmax < 0 || nmax > MAXSMALLINT) + error->one("Per-processor system is too big"); tag = atom->tag = (int *) memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); diff --git a/src/atom_vec_charge.cpp b/src/atom_vec_charge.cpp index 76b69b4bd7..69a918562f 100644 --- a/src/atom_vec_charge.cpp +++ b/src/atom_vec_charge.cpp @@ -13,6 +13,7 @@ #include "stdlib.h" #include "atom_vec_charge.h" +#include "lmptype.h" #include "atom.h" #include "domain.h" #include "modify.h" @@ -55,6 +56,8 @@ void AtomVecCharge::grow(int n) if (n == 0) nmax += DELTA; else nmax = n; atom->nmax = nmax; + if (nmax < 0 || nmax > MAXSMALLINT) + error->one("Per-processor system is too big"); tag = atom->tag = (int *) memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); diff --git a/src/atom_vec_hybrid.cpp b/src/atom_vec_hybrid.cpp index 02bc5df281..8be54a1029 100644 --- a/src/atom_vec_hybrid.cpp +++ b/src/atom_vec_hybrid.cpp @@ -14,6 +14,7 @@ #include "stdlib.h" #include "string.h" #include "atom_vec_hybrid.h" +#include "lmptype.h" #include "atom.h" #include "domain.h" #include "modify.h" @@ -112,6 +113,8 @@ void AtomVecHybrid::grow(int n) if (n == 0) nmax += DELTA; else nmax = n; atom->nmax = nmax; + if (nmax < 0 || nmax > MAXSMALLINT) + error->one("Per-processor system is too big"); // sub-styles perform all reallocation // turn off nextra_grow so hybrid can do that once below diff --git a/src/create_atoms.cpp b/src/create_atoms.cpp index 98acf8dda9..60f823909c 100644 --- a/src/create_atoms.cpp +++ b/src/create_atoms.cpp @@ -170,14 +170,18 @@ void CreateAtoms::command(int narg, char **arg) bigint nblocal = atom->nlocal; MPI_Allreduce(&nblocal,&atom->natoms,1,MPI_LMP_BIGINT,MPI_SUM,world); + if (atom->natoms < 0 || atom->natoms > MAXBIGINT) + error->all("Too many total atoms"); // print status if (comm->me == 0) { + char str[32]; + sprintf(str,"Created %s atoms\n",BIGINT_FORMAT); if (screen) - fprintf(screen,"Created %lu atoms\n",atom->natoms-natoms_previous); + fprintf(screen,str,atom->natoms-natoms_previous); if (logfile) - fprintf(logfile,"Created %lu atoms\n",atom->natoms-natoms_previous); + fprintf(logfile,str,atom->natoms-natoms_previous); } // reset simulation now that more atoms are defined diff --git a/src/delete_atoms.cpp b/src/delete_atoms.cpp index d3a2bed8ea..f140c52372 100644 --- a/src/delete_atoms.cpp +++ b/src/delete_atoms.cpp @@ -105,10 +105,11 @@ void DeleteAtoms::command(int narg, char **arg) bigint ndelete = natoms_previous - atom->natoms; if (comm->me == 0) { - if (screen) fprintf(screen,"Deleted %lu atoms, new total = %lu\n", - ndelete,atom->natoms); - if (logfile) fprintf(logfile,"Deleted %lu atoms, new total = %lu\n", - ndelete,atom->natoms); + char str[64]; + sprintf(str,"Deleted %s atoms, new total = %s\n", + BIGINT_FORMAT,BIGINT_FORMAT); + if (screen) fprintf(screen,str,ndelete,atom->natoms); + if (logfile) fprintf(logfile,str,ndelete,atom->natoms); } } diff --git a/src/delete_bonds.cpp b/src/delete_bonds.cpp index 9bf92c512d..0b1ff6daec 100644 --- a/src/delete_bonds.cpp +++ b/src/delete_bonds.cpp @@ -445,35 +445,35 @@ void DeleteBonds::command(int narg, char **arg) } if (comm->me == 0) { - if (screen) { - if (atom->avec->bonds_allow) - fprintf(screen," %lu total bonds, %lu turned on, %lu turned off\n", - atom->nbonds,bond_on,bond_off); - if (atom->avec->angles_allow) - fprintf(screen," %lu total angles, %lu turned on, %lu turned off\n", - atom->nangles,angle_on,angle_off); - if (atom->avec->dihedrals_allow) - fprintf(screen," %lu total dihedrals, %lu turned on, %lu turned off\n", - atom->ndihedrals,dihedral_on,dihedral_off); - if (atom->avec->impropers_allow) - fprintf(screen," %lu total impropers, %lu turned on, %lu turned off\n", - atom->nimpropers,improper_on,improper_off); + if (atom->avec->bonds_allow) { + char str[128]; + sprintf(str," %s total bonds, %s turned on, %s turned off\n", + BIGINT_FORMAT,BIGINT_FORMAT,BIGINT_FORMAT); + if (screen) fprintf(screen,str,atom->nbonds,bond_on,bond_off); + if (logfile) fprintf(logfile,str,atom->nbonds,bond_on,bond_off); } - if (logfile) { - if (atom->avec->bonds_allow) - fprintf(logfile," %lu total bonds, %lu turned on, %lu turned off\n", - atom->nbonds,bond_on,bond_off); - if (atom->avec->angles_allow) - fprintf(logfile," %lu total angles, %lu turned on, %lu turned off\n", - atom->nangles,angle_on,angle_off); - if (atom->avec->dihedrals_allow) - fprintf(logfile," %lu total dihedrals, %lu turned on, " - "%lu turned off\n", - atom->ndihedrals,dihedral_on,dihedral_off); - if (atom->avec->impropers_allow) - fprintf(logfile," %lu total impropers, %lu turned on, " - "%lu turned off\n", - atom->nimpropers,improper_on,improper_off); + if (atom->avec->angles_allow) { + char str[128]; + sprintf(str," %s total angles, %s turned on, %s turned off\n", + BIGINT_FORMAT,BIGINT_FORMAT,BIGINT_FORMAT); + if (screen) fprintf(screen,str,atom->nangles,angle_on,angle_off); + if (logfile) fprintf(logfile,str,atom->nangles,angle_on,angle_off); + } + if (atom->avec->dihedrals_allow) { + char str[128]; + sprintf(str," %s total dihedrals, %s turned on, %s turned off\n", + BIGINT_FORMAT,BIGINT_FORMAT,BIGINT_FORMAT); + if (screen) fprintf(screen,str,atom->ndihedrals,dihedral_on,dihedral_off); + if (logfile) fprintf(logfile,str, + atom->ndihedrals,dihedral_on,dihedral_off); + } + if (atom->avec->impropers_allow) { + char str[128]; + sprintf(str," %s total impropers, %s turned on, %s turned off\n", + BIGINT_FORMAT,BIGINT_FORMAT,BIGINT_FORMAT); + if (screen) fprintf(screen,str,atom->nimpropers,improper_on,improper_off); + if (logfile) fprintf(logfile,str, + atom->nimpropers,improper_on,improper_off); } } diff --git a/src/displace_atoms.cpp b/src/displace_atoms.cpp index ff55334237..1e93c919bf 100644 --- a/src/displace_atoms.cpp +++ b/src/displace_atoms.cpp @@ -215,9 +215,10 @@ void DisplaceAtoms::command(int narg, char **arg) bigint nblocal = atom->nlocal; MPI_Allreduce(&nblocal,&natoms,1,MPI_LMP_BIGINT,MPI_SUM,world); if (natoms != atom->natoms) { - char str[128]; - sprintf(str,"Lost atoms via displace_atoms: original %lu current %lu", - atom->natoms,natoms); + char fstr[64],str[128]; + sprintf(fstr,"Lost atoms via displace_atoms: original %s current %s", + BIGINT_FORMAT,BIGINT_FORMAT); + sprintf(str,fstr,atom->natoms,natoms); error->all(str); } } diff --git a/src/displace_box.cpp b/src/displace_box.cpp index ece73177d5..e80ddbbd3f 100644 --- a/src/displace_box.cpp +++ b/src/displace_box.cpp @@ -381,9 +381,10 @@ void DisplaceBox::command(int narg, char **arg) bigint nblocal = atom->nlocal; MPI_Allreduce(&nblocal,&natoms,1,MPI_LMP_BIGINT,MPI_SUM,world); if (natoms != atom->natoms) { - char str[128]; - sprintf(str,"Lost atoms via displace_box: original %lu current %lu", - atom->natoms,natoms); + char fstr[64],str[128]; + sprintf(fstr,"Lost atoms via displace_box: original %s current %s", + BIGINT_FORMAT,BIGINT_FORMAT); + sprintf(str,fstr,atom->natoms,natoms); error->all(str); } } diff --git a/src/dump.cpp b/src/dump.cpp index c0939f2453..53c6ff35f2 100644 --- a/src/dump.cpp +++ b/src/dump.cpp @@ -253,6 +253,7 @@ void Dump::write() // nme = # of dump lines this proc will contribute to dump nme = count(); + bigint bnme = nme; // ntotal = total # of dump lines // nmax = max # of dump lines on any proc @@ -260,21 +261,24 @@ void Dump::write() int nmax; if (multiproc) nmax = nme; else { - MPI_Allreduce(&nme,&ntotal,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&bnme,&ntotal,1,MPI_LMP_BIGINT,MPI_SUM,world); MPI_Allreduce(&nme,&nmax,1,MPI_INT,MPI_MAX,world); } // write timestep header - if (multiproc) write_header(nme); + if (multiproc) write_header(bnme); else write_header(ntotal); - // this insures proc 0 can receive everyone's info + // insure proc 0 can receive everyone's info + // limit nmax*size_one to int since used as arg in MPI_Rsend() below // pack my data into buf // if sorting on IDs also request ID list from pack() // sort buf as needed if (nmax > maxbuf) { + if ((bigint) nmax * size_one > MAXSMALLINT) + error->all("Too much per-proc info for dump"); maxbuf = nmax; memory->sfree(buf); buf = (double *) diff --git a/src/dump.h b/src/dump.h index 6fea5482bb..4b4aeb289d 100644 --- a/src/dump.h +++ b/src/dump.h @@ -16,6 +16,7 @@ #include "stdio.h" #include "pointers.h" +#include "lmptype.h" namespace LAMMPS_NS { @@ -69,7 +70,7 @@ class Dump : protected Pointers { double boxzlo,boxzhi; double boxxy,boxxz,boxyz; - int ntotal; // # of per-atom lines in snapshot + bigint ntotal; // # of per-atom lines in snapshot int reorderflag; // 1 if OK to reorder instead of sort int ntotal_reorder; // # of atoms that must be in snapshot int nme_reorder; // # of atoms I must own in snapshot @@ -91,7 +92,7 @@ class Dump : protected Pointers { virtual void init_style() = 0; virtual void openfile(); virtual int modify_param(int, char **) {return 0;} - virtual void write_header(int) = 0; + virtual void write_header(bigint) = 0; virtual int count() = 0; virtual void pack(int *) = 0; virtual void write_data(int, double *) = 0; diff --git a/src/dump_atom.cpp b/src/dump_atom.cpp index 930fc6e1d3..1b3b0c2545 100644 --- a/src/dump_atom.cpp +++ b/src/dump_atom.cpp @@ -123,7 +123,7 @@ int DumpAtom::modify_param(int narg, char **arg) /* ---------------------------------------------------------------------- */ -void DumpAtom::write_header(int ndump) +void DumpAtom::write_header(bigint ndump) { if (multiproc) (this->*header_choice)(ndump); else if (me == 0) (this->*header_choice)(ndump); @@ -160,10 +160,10 @@ void DumpAtom::write_data(int n, double *mybuf) /* ---------------------------------------------------------------------- */ -void DumpAtom::header_binary(int ndump) +void DumpAtom::header_binary(bigint ndump) { fwrite(&update->ntimestep,sizeof(int),1,fp); - fwrite(&ndump,sizeof(int),1,fp); + fwrite(&ndump,sizeof(bigint),1,fp); fwrite(&domain->triclinic,sizeof(int),1,fp); fwrite(&boxxlo,sizeof(double),1,fp); fwrite(&boxxhi,sizeof(double),1,fp); @@ -180,10 +180,10 @@ void DumpAtom::header_binary(int ndump) /* ---------------------------------------------------------------------- */ -void DumpAtom::header_binary_triclinic(int ndump) +void DumpAtom::header_binary_triclinic(bigint ndump) { fwrite(&update->ntimestep,sizeof(int),1,fp); - fwrite(&ndump,sizeof(int),1,fp); + fwrite(&ndump,sizeof(bigint),1,fp); fwrite(&domain->triclinic,sizeof(int),1,fp); fwrite(&boxxlo,sizeof(double),1,fp); fwrite(&boxxhi,sizeof(double),1,fp); @@ -203,12 +203,12 @@ void DumpAtom::header_binary_triclinic(int ndump) /* ---------------------------------------------------------------------- */ -void DumpAtom::header_item(int ndump) +void DumpAtom::header_item(bigint ndump) { fprintf(fp,"ITEM: TIMESTEP\n"); fprintf(fp,"%d\n",update->ntimestep); fprintf(fp,"ITEM: NUMBER OF ATOMS\n"); - fprintf(fp,"%d\n",ndump); + fprintf(fp,BIGINT_FORMAT_NL,ndump); fprintf(fp,"ITEM: BOX BOUNDS\n"); fprintf(fp,"%g %g\n",boxxlo,boxxhi); fprintf(fp,"%g %g\n",boxylo,boxyhi); @@ -218,12 +218,12 @@ void DumpAtom::header_item(int ndump) /* ---------------------------------------------------------------------- */ -void DumpAtom::header_item_triclinic(int ndump) +void DumpAtom::header_item_triclinic(bigint ndump) { fprintf(fp,"ITEM: TIMESTEP\n"); fprintf(fp,"%d\n",update->ntimestep); fprintf(fp,"ITEM: NUMBER OF ATOMS\n"); - fprintf(fp,"%d\n",ndump); + fprintf(fp,BIGINT_FORMAT_NL,ndump); fprintf(fp,"ITEM: BOX BOUNDS xy xz yz\n"); fprintf(fp,"%g %g %g\n",boxxlo,boxxhi,boxxy); fprintf(fp,"%g %g %g\n",boxylo,boxyhi,boxxz); diff --git a/src/dump_atom.h b/src/dump_atom.h index 14f8e75248..0483a7d643 100644 --- a/src/dump_atom.h +++ b/src/dump_atom.h @@ -36,17 +36,17 @@ class DumpAtom : public Dump { void init_style(); int modify_param(int, char **); - void write_header(int); + void write_header(bigint); int count(); void pack(int *); void write_data(int, double *); - typedef void (DumpAtom::*FnPtrHeader)(int); + typedef void (DumpAtom::*FnPtrHeader)(bigint); FnPtrHeader header_choice; // ptr to write header functions - void header_binary(int); - void header_binary_triclinic(int); - void header_item(int); - void header_item_triclinic(int); + void header_binary(bigint); + void header_binary_triclinic(bigint); + void header_item(bigint); + void header_item_triclinic(bigint); typedef void (DumpAtom::*FnPtrPack)(int *); FnPtrPack pack_choice; // ptr to pack functions diff --git a/src/dump_cfg.cpp b/src/dump_cfg.cpp index b11a5169b1..924c09eaf8 100755 --- a/src/dump_cfg.cpp +++ b/src/dump_cfg.cpp @@ -184,10 +184,12 @@ void DumpCFG::init_style() /* ---------------------------------------------------------------------- */ -void DumpCFG::write_header(int n) +void DumpCFG::write_header(bigint n) { if (me == 0 || multiproc) { - fprintf(fp,"Number of particles = %d\n", n); + char str[64]; + sprintf(str,"Number of particles = %s\n",BIGINT_FORMAT); + fprintf(fp,str,n); fprintf(fp,"A = 1.0 Angstrom (basic length-scale)\n"); fprintf(fp,"H0(1,1) = %g A\n",domain->xprd); fprintf(fp,"H0(1,2) = 0 A \n"); diff --git a/src/dump_cfg.h b/src/dump_cfg.h index ca3cd4032c..0467983f76 100755 --- a/src/dump_cfg.h +++ b/src/dump_cfg.h @@ -38,7 +38,7 @@ class DumpCFG : public DumpCustom { double **rbuf; // buf of data lines for data lines rearrangement void init_style(); - void write_header(int); + void write_header(bigint); void write_data(int, double *); int modify_param2(int, char **); diff --git a/src/dump_custom.cpp b/src/dump_custom.cpp index c5058d89fd..a2d9f36c13 100644 --- a/src/dump_custom.cpp +++ b/src/dump_custom.cpp @@ -236,7 +236,7 @@ void DumpCustom::init_style() /* ---------------------------------------------------------------------- */ -void DumpCustom::write_header(int ndump) +void DumpCustom::write_header(bigint ndump) { if (multiproc) (this->*header_choice)(ndump); else if (me == 0) (this->*header_choice)(ndump); @@ -244,10 +244,10 @@ void DumpCustom::write_header(int ndump) /* ---------------------------------------------------------------------- */ -void DumpCustom::header_binary(int ndump) +void DumpCustom::header_binary(bigint ndump) { fwrite(&update->ntimestep,sizeof(int),1,fp); - fwrite(&ndump,sizeof(int),1,fp); + fwrite(&ndump,sizeof(bigint),1,fp); fwrite(&domain->triclinic,sizeof(int),1,fp); fwrite(&boxxlo,sizeof(double),1,fp); fwrite(&boxxhi,sizeof(double),1,fp); @@ -264,10 +264,10 @@ void DumpCustom::header_binary(int ndump) /* ---------------------------------------------------------------------- */ -void DumpCustom::header_binary_triclinic(int ndump) +void DumpCustom::header_binary_triclinic(bigint ndump) { fwrite(&update->ntimestep,sizeof(int),1,fp); - fwrite(&ndump,sizeof(int),1,fp); + fwrite(&ndump,sizeof(bigint),1,fp); fwrite(&domain->triclinic,sizeof(int),1,fp); fwrite(&boxxlo,sizeof(double),1,fp); fwrite(&boxxhi,sizeof(double),1,fp); @@ -287,12 +287,12 @@ void DumpCustom::header_binary_triclinic(int ndump) /* ---------------------------------------------------------------------- */ -void DumpCustom::header_item(int ndump) +void DumpCustom::header_item(bigint ndump) { fprintf(fp,"ITEM: TIMESTEP\n"); fprintf(fp,"%d\n",update->ntimestep); fprintf(fp,"ITEM: NUMBER OF ATOMS\n"); - fprintf(fp,"%d\n",ndump); + fprintf(fp,BIGINT_FORMAT_NL,ndump); fprintf(fp,"ITEM: BOX BOUNDS\n"); fprintf(fp,"%g %g\n",boxxlo,boxxhi); fprintf(fp,"%g %g\n",boxylo,boxyhi); @@ -302,12 +302,12 @@ void DumpCustom::header_item(int ndump) /* ---------------------------------------------------------------------- */ -void DumpCustom::header_item_triclinic(int ndump) +void DumpCustom::header_item_triclinic(bigint ndump) { fprintf(fp,"ITEM: TIMESTEP\n"); fprintf(fp,"%d\n",update->ntimestep); fprintf(fp,"ITEM: NUMBER OF ATOMS\n"); - fprintf(fp,"%d\n",ndump); + fprintf(fp,BIGINT_FORMAT_NL,ndump); fprintf(fp,"ITEM: BOX BOUNDS xy xz yz\n"); fprintf(fp,"%g %g %g\n",boxxlo,boxxhi,boxxy); fprintf(fp,"%g %g %g\n",boxylo,boxyhi,boxxz); diff --git a/src/dump_custom.h b/src/dump_custom.h index 18be848f00..0f7913272f 100644 --- a/src/dump_custom.h +++ b/src/dump_custom.h @@ -70,7 +70,7 @@ class DumpCustom : public Dump { // private methods virtual void init_style(); - virtual void write_header(int); + virtual void write_header(bigint); int count(); void pack(int *); virtual void write_data(int, double *); @@ -83,12 +83,12 @@ class DumpCustom : public Dump { int modify_param(int, char **); virtual int modify_param2(int, char **) {return 0;} - typedef void (DumpCustom::*FnPtrHeader)(int); + typedef void (DumpCustom::*FnPtrHeader)(bigint); FnPtrHeader header_choice; // ptr to write header functions - void header_binary(int); - void header_binary_triclinic(int); - void header_item(int); - void header_item_triclinic(int); + void header_binary(bigint); + void header_binary_triclinic(bigint); + void header_item(bigint); + void header_item_triclinic(bigint); typedef void (DumpCustom::*FnPtrData)(int, double *); FnPtrData write_choice; // ptr to write data functions diff --git a/src/dump_dcd.cpp b/src/dump_dcd.cpp index 1a8743ae76..90f51e0a26 100644 --- a/src/dump_dcd.cpp +++ b/src/dump_dcd.cpp @@ -68,11 +68,9 @@ DumpDCD::DumpDCD(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg) // allocate global array for atom coords - bigint n; - if (igroup == 0) n = static_cast (atom->natoms); - else n = static_cast (group->count(igroup)); + bigint n = group->count(igroup); if (n > MAXSMALLINT) error->all("Too many atoms for dump dcd"); - natoms = n; + natoms = static_cast (n); coords = (float *) memory->smalloc(3*natoms*sizeof(float),"dump:coords"); xf = &coords[0*natoms]; @@ -124,7 +122,7 @@ void DumpDCD::openfile() /* ---------------------------------------------------------------------- */ -void DumpDCD::write_header(int n) +void DumpDCD::write_header(bigint n) { if (n != natoms) error->all("Dump dcd of non-matching # of atoms"); diff --git a/src/dump_dcd.h b/src/dump_dcd.h index fc5e51668d..c71f154acb 100644 --- a/src/dump_dcd.h +++ b/src/dump_dcd.h @@ -40,7 +40,7 @@ class DumpDCD : public Dump { void init_style(); void openfile(); - void write_header(int); + void write_header(bigint); int count(); void pack(int *); void write_data(int, double *); diff --git a/src/dump_local.cpp b/src/dump_local.cpp index c93beac713..f4832df096 100644 --- a/src/dump_local.cpp +++ b/src/dump_local.cpp @@ -187,13 +187,13 @@ int DumpLocal::modify_param(int narg, char **arg) /* ---------------------------------------------------------------------- */ -void DumpLocal::write_header(int ndump) +void DumpLocal::write_header(bigint ndump) { if (me == 0) { fprintf(fp,"ITEM: TIMESTEP\n"); fprintf(fp,"%d\n",update->ntimestep); fprintf(fp,"ITEM: NUMBER OF %s\n",label); - fprintf(fp,"%d\n",ndump); + fprintf(fp,BIGINT_FORMAT_NL,ndump); fprintf(fp,"ITEM: %s %s\n",label,columns); } } diff --git a/src/dump_local.h b/src/dump_local.h index 53173d7910..cc2fedf96d 100644 --- a/src/dump_local.h +++ b/src/dump_local.h @@ -55,7 +55,7 @@ class DumpLocal : public Dump { void init_style(); int modify_param(int, char **); - void write_header(int); + void write_header(bigint); int count(); void pack(int *); void write_data(int, double *); diff --git a/src/dump_xyz.cpp b/src/dump_xyz.cpp index 93d6294aa8..06c0686e7b 100644 --- a/src/dump_xyz.cpp +++ b/src/dump_xyz.cpp @@ -58,10 +58,10 @@ void DumpXYZ::init_style() /* ---------------------------------------------------------------------- */ -void DumpXYZ::write_header(int n) +void DumpXYZ::write_header(bigint n) { if (me == 0) { - fprintf(fp,"%d\n",n); + fprintf(fp,BIGINT_FORMAT_NL,n); fprintf(fp,"Atoms\n"); } } diff --git a/src/dump_xyz.h b/src/dump_xyz.h index b155805113..39e6d5d196 100644 --- a/src/dump_xyz.h +++ b/src/dump_xyz.h @@ -31,7 +31,7 @@ class DumpXYZ : public Dump { private: void init_style(); - void write_header(int); + void write_header(bigint); int count(); void pack(int *); void write_data(int, double *); diff --git a/src/finish.cpp b/src/finish.cpp index 5d148a7be5..92496b5b9a 100644 --- a/src/finish.cpp +++ b/src/finish.cpp @@ -89,14 +89,11 @@ void Finish::end(int flag) MPI_Allreduce(&nblocal,&natoms,1,MPI_LMP_BIGINT,MPI_SUM,world); if (me == 0) { - if (screen) - fprintf(screen, - "Loop time of %g on %d procs for %d steps with %lu atoms\n", - time_loop,nprocs,update->nsteps,natoms); - if (logfile) - fprintf(logfile, - "Loop time of %g on %d procs for %d steps with %lu atoms\n", - time_loop,nprocs,update->nsteps,natoms); + char str[128]; + sprintf(str,"Loop time of %%g on %%d procs for %%d steps with %s atoms\n", + BIGINT_FORMAT); + if (screen) fprintf(screen,str,time_loop,nprocs,update->nsteps,natoms); + if (logfile) fprintf(logfile,str,time_loop,nprocs,update->nsteps,natoms); } if (time_loop == 0.0) time_loop = 1.0; diff --git a/src/fix_deposit.cpp b/src/fix_deposit.cpp index 60fc34ed65..357a325942 100644 --- a/src/fix_deposit.cpp +++ b/src/fix_deposit.cpp @@ -322,22 +322,23 @@ void FixDeposit::pre_exchange() // warn if not successful b/c too many attempts or no proc owned particle - if (comm->me == 0) - if (success == 0) - error->warning("Particle deposition was unsuccessful",0); + if (!success && comm->me == 0) + error->warning("Particle deposition was unsuccessful",0); - // set tag # of new particle beyond all previous atoms // reset global natoms + // set tag # of new particle beyond all previous atoms // if global map exists, reset it now instead of waiting for comm // since deleting atoms messes up ghosts - if (success && atom->tag_enable) { - atom->tag_extend(); + if (success) { atom->natoms += 1; - if (atom->map_style) { - atom->nghost = 0; - atom->map_init(); - atom->map_set(); + if (atom->tag_enable) { + atom->tag_extend(); + if (atom->map_style) { + atom->nghost = 0; + atom->map_init(); + atom->map_set(); + } } } diff --git a/src/fix_orient_fcc.cpp b/src/fix_orient_fcc.cpp index 5a7ea44709..5f7fdc0680 100644 --- a/src/fix_orient_fcc.cpp +++ b/src/fix_orient_fcc.cpp @@ -403,18 +403,17 @@ void FixOrientFCC::post_force(int vflag) MPI_Allreduce(&maxcount,&max,1,MPI_INT,MPI_MAX,world); if (me == 0) { - if (screen) { - fprintf(screen,"orient step %d: %lu atoms have %d neighbors\n", - update->ntimestep,atom->natoms,total); + char str[64]; + sprintf(str,"orient step %%d: %s atoms have %%d neighbors\n", + BIGINT_FORMAT); + if (screen) fprintf(screen,str,update->ntimestep,atom->natoms,total); + if (logfile) fprintf(logfile,str,update->ntimestep,atom->natoms,total); + if (screen) fprintf(screen," neighs: min = %d, max = %d, ave = %g\n", min,max,ave); - } - if (logfile) { - fprintf(logfile,"orient step %d: %lu atoms have %d neighbors\n", - update->ntimestep,atom->natoms,total); + if (logfile) fprintf(logfile," neighs: min = %d, max = %d, ave = %g\n", min,max,ave); - } } } } diff --git a/src/lammps.cpp b/src/lammps.cpp index 920f336768..97b07922a3 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -241,15 +241,22 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) } } - // check datatype sizes + // check datatype settings in lmptype.h - if (sizeof(bigint) != 8) - error->all("No support for 8-byte unsigned integers"); + if (sizeof(smallint) != sizeof(int)) + error->all("Smallint setting in lmptype.h is invalid"); + if (sizeof(tagint) < sizeof(smallint)) + error->all("Tagint setting in lmptype.h is invalid"); + if (sizeof(bigint) < sizeof(tagint)) + error->all("Bigint setting in lmptype.h is invalid"); int mpisize; + MPI_Type_size(MPI_LMP_TAGINT,&mpisize); + if (mpisize != sizeof(tagint)) + error->all("MPI_LMP_TAGINT and tagint in lmptype.h are not compatible"); MPI_Type_size(MPI_LMP_BIGINT,&mpisize); - if (mpisize != 8) - error->all("MPI_LMP_BIGINT is not 8-byte data type"); + if (mpisize != sizeof(bigint)) + error->all("MPI_LMP_BIGINT and bigint in lmptype.h are not compatible"); // allocate input class now that MPI is fully setup diff --git a/src/lmptype.h b/src/lmptype.h index 82c4644e7e..017ef05da4 100644 --- a/src/lmptype.h +++ b/src/lmptype.h @@ -15,11 +15,12 @@ // smallint = variables for system on 1 processor (nlocal, etc) // tagint = variables for atom IDs (tag) -// bigint = variables for total system and timesteps (natoms, ntimestep, etc) +// bigint = variables for total system (natoms, ntimestep, etc) // smallint must be an int, as defined by C compiler // tagint can be 32-bit or 64-bit int, must be >= smallint -// bigint can be 32-bit or 64-bit int, must be >= smallint and >= tagint +// NOTE: 64-bit tagint is not yet supported +// bigint can be 32-bit or 64-bit int, must be >= tagint // MAXSMALLINT = max value of a smallint // MAXTAGINT = max value of a tagint @@ -27,6 +28,8 @@ // MPI_LMP_TAGINT = MPI data type corresponding to tagint // MPI_LMP_BIGINT = MPI data type corresponding to bigint +// NOTE: you may need to set MPI_LMP_BIGINT to MPI_LONG +// if your machine/MPI does not support "long long" data types #ifndef LMP_LMPTYPE_H #define LMP_LMPTYPE_H @@ -35,7 +38,8 @@ namespace LAMMPS_NS { -// default settings: 4-byte smallint, 4-byte tagint, 8-byte bigint +// default settings +// 32-bit smallint and tagint, 64-bit bigint typedef int smallint; typedef int tagint; @@ -48,6 +52,54 @@ typedef int64_t bigint; #define MPI_LMP_TAGINT MPI_INT #define MPI_LMP_BIGINT MPI_LONG_LONG +#define TAGINT_FORMAT "%d" +#define BIGINT_FORMAT "%ld" +#define TAGINT_FORMAT_NL "%d\n" +#define BIGINT_FORMAT_NL "%ld\n" + +// for molecular problems that exceed 2 billion (2^31) atoms +// 32-bit smallint, 64-bit tagint and bigint +// NOTE: 64-bit tagint is not yet supported + +/* +typedef int smallint; +typedef int64_t tagint; +typedef int64_t bigint; + +#define MAXSMALLINT 0x7FFFFFFF +#define MAXTAGINT 0x7FFFFFFFFFFFFFFFL +#define MAXBIGINT 0x7FFFFFFFFFFFFFFFL + +#define MPI_LMP_TAGINT MPI_LONG_LONG +#define MPI_LMP_BIGINT MPI_LONG_LONG + +#define TAGINT_FORMAT "%ld" +#define BIGINT_FORMAT "%ld" +#define TAGINT_FORMAT_NL "%ld\n" +#define BIGINT_FORMAT_NL "%ld\n" +*/ + +// for machines that don't support 64-bit ints +// 32-bit smallint and tagint and bigint + +/* +typedef int smallint; +typedef int tagint; +typedef int bigint; + +#define MAXSMALLINT 0x7FFFFFFF +#define MAXTAGINT 0x7FFFFFFF +#define MAXBIGINT 0x7FFFFFFF + +#define MPI_LMP_TAGINT MPI_INT +#define MPI_LMP_BIGINT MPI_INT + +#define TAGINT_FORMAT "%d" +#define BIGINT_FORMAT "%d" +#define TAGINT_FORMAT_NL "%d\n" +#define BIGINT_FORMAT_NL "%d\n" +*/ + } #endif diff --git a/src/read_data.cpp b/src/read_data.cpp index 92a1fef909..b38f228698 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -336,11 +336,14 @@ void ReadData::header(int flag) // search line for header keyword and set corresponding variable - if (strstr(line,"atoms")) sscanf(line,"%lu",&atom->natoms); - else if (strstr(line,"bonds")) sscanf(line,"%lu",&atom->nbonds); - else if (strstr(line,"angles")) sscanf(line,"%lu",&atom->nangles); - else if (strstr(line,"dihedrals")) sscanf(line,"%lu",&atom->ndihedrals); - else if (strstr(line,"impropers")) sscanf(line,"%lu",&atom->nimpropers); + if (strstr(line,"atoms")) sscanf(line,BIGINT_FORMAT,&atom->natoms); + + else if (strstr(line,"bonds")) sscanf(line,BIGINT_FORMAT,&atom->nbonds); + else if (strstr(line,"angles")) sscanf(line,BIGINT_FORMAT,&atom->nangles); + else if (strstr(line,"dihedrals")) sscanf(line,BIGINT_FORMAT, + &atom->ndihedrals); + else if (strstr(line,"impropers")) sscanf(line,BIGINT_FORMAT, + &atom->nimpropers); else if (strstr(line,"atom types")) sscanf(line,"%d",&atom->ntypes); else if (strstr(line,"bond types")) sscanf(line,"%d",&atom->nbondtypes); @@ -365,6 +368,17 @@ void ReadData::header(int flag) } else break; } + // error check on total system size + + if (atom->natoms < 0 || atom->natoms > MAXBIGINT || + atom->nbonds < 0 || atom->nbonds > MAXBIGINT || + atom->nangles < 0 || atom->nangles > MAXBIGINT || + atom->ndihedrals < 0 || atom->ndihedrals > MAXBIGINT || + atom->nimpropers < 0 || atom->nimpropers > MAXBIGINT) { + if (flag == 0) error->one("System in data file is too big"); + else error->all("System in data file is too big"); + } + // check that exiting string is a valid section keyword parse_keyword(1,flag); @@ -438,8 +452,10 @@ void ReadData::atoms() MPI_Allreduce(&tmp,&natoms,1,MPI_LMP_BIGINT,MPI_SUM,world); if (me == 0) { - if (screen) fprintf(screen," %lu atoms\n",natoms); - if (logfile) fprintf(logfile," %lu atoms\n",natoms); + char str[32]; + sprintf(str," %s atoms\n",BIGINT_FORMAT); + if (screen) fprintf(screen,str,natoms); + if (logfile) fprintf(logfile,str,natoms); } if (natoms != atom->natoms) error->all("Did not assign all atoms correctly"); @@ -529,8 +545,10 @@ void ReadData::velocities() } if (me == 0) { - if (screen) fprintf(screen," %lu velocities\n",natoms); - if (logfile) fprintf(logfile," %lu velocities\n",natoms); + char str[32]; + sprintf(str," %s velocities\n",BIGINT_FORMAT); + if (screen) fprintf(screen,str,natoms); + if (logfile) fprintf(logfile,str,natoms); } } @@ -573,8 +591,10 @@ void ReadData::bonds() if (!force->newton_bond) factor = 2; if (me == 0) { - if (screen) fprintf(screen," %lu bonds\n",sum/factor); - if (logfile) fprintf(logfile," %lu bonds\n",sum/factor); + char str[32]; + sprintf(str," %s bonds\n",BIGINT_FORMAT); + if (screen) fprintf(screen,str,sum/factor); + if (logfile) fprintf(logfile,str,sum/factor); } if (sum != factor*atom->nbonds) error->all("Bonds assigned incorrectly"); } @@ -618,8 +638,10 @@ void ReadData::angles() if (!force->newton_bond) factor = 3; if (me == 0) { - if (screen) fprintf(screen," %lu angles\n",sum/factor); - if (logfile) fprintf(logfile," %lu angles\n",sum/factor); + char str[32]; + sprintf(str," %s angles\n",BIGINT_FORMAT); + if (screen) fprintf(screen,str,sum/factor); + if (logfile) fprintf(logfile,str,sum/factor); } if (sum != factor*atom->nangles) error->all("Angles assigned incorrectly"); } @@ -663,8 +685,10 @@ void ReadData::dihedrals() if (!force->newton_bond) factor = 4; if (me == 0) { - if (screen) fprintf(screen," %lu dihedrals\n",sum/factor); - if (logfile) fprintf(logfile," %lu dihedrals\n",sum/factor); + char str[32]; + sprintf(str," %s dihedrals\n",BIGINT_FORMAT); + if (screen) fprintf(screen,str,sum/factor); + if (logfile) fprintf(logfile,str,sum/factor); } if (sum != factor*atom->ndihedrals) error->all("Dihedrals assigned incorrectly"); @@ -709,8 +733,10 @@ void ReadData::impropers() if (!force->newton_bond) factor = 4; if (me == 0) { - if (screen) fprintf(screen," %lu impropers\n",sum/factor); - if (logfile) fprintf(logfile," %lu impropers\n",sum/factor); + char str[32]; + sprintf(str," %s impropers\n",BIGINT_FORMAT); + if (screen) fprintf(screen,str,sum/factor); + if (logfile) fprintf(logfile,str,sum/factor); } if (sum != factor*atom->nimpropers) error->all("Impropers assigned incorrectly"); diff --git a/src/read_restart.cpp b/src/read_restart.cpp index 0078a8324d..d8501a7bf9 100644 --- a/src/read_restart.cpp +++ b/src/read_restart.cpp @@ -43,7 +43,8 @@ using namespace LAMMPS_NS; // same as write_restart.cpp -enum{VERSION,UNITS,NTIMESTEP,DIMENSION,NPROCS,PROCGRID_0,PROCGRID_1,PROCGRID_2, +enum{VERSION,SMALLINT,TAGINT,BIGINT, + UNITS,NTIMESTEP,DIMENSION,NPROCS,PROCGRID_0,PROCGRID_1,PROCGRID_2, NEWTON_PAIR,NEWTON_BOND,XPERIODIC,YPERIODIC,ZPERIODIC, BOUNDARY_00,BOUNDARY_01,BOUNDARY_10,BOUNDARY_11,BOUNDARY_20,BOUNDARY_21, ATOM_STYLE,NATOMS,NTYPES, @@ -296,28 +297,38 @@ void ReadRestart::command(int narg, char **arg) MPI_Allreduce(&nblocal,&natoms,1,MPI_LMP_BIGINT,MPI_SUM,world); if (me == 0) { - if (screen) fprintf(screen," %lu atoms\n",natoms); - if (logfile) fprintf(logfile," %lu atoms\n",natoms); + char str[32]; + sprintf(str," %s atoms\n",BIGINT_FORMAT); + if (screen) fprintf(screen,str,natoms); + if (logfile) fprintf(logfile,str,natoms); } if (natoms != atom->natoms) error->all("Did not assign all atoms correctly"); if (me == 0) { if (atom->nbonds) { - if (screen) fprintf(screen," %lu bonds\n",atom->nbonds); - if (logfile) fprintf(logfile," %lu bonds\n",atom->nbonds); + char str[32]; + sprintf(str," %s bonds\n",BIGINT_FORMAT); + if (screen) fprintf(screen,str,atom->nbonds); + if (logfile) fprintf(logfile,str,atom->nbonds); } if (atom->nangles) { - if (screen) fprintf(screen," %lu angles\n",atom->nangles); - if (logfile) fprintf(logfile," %lu angles\n",atom->nangles); + char str[32]; + sprintf(str," %s angles\n",BIGINT_FORMAT); + if (screen) fprintf(screen,str,atom->nangles); + if (logfile) fprintf(logfile,str,atom->nangles); } if (atom->ndihedrals) { - if (screen) fprintf(screen," %lu dihedrals\n",atom->ndihedrals); - if (logfile) fprintf(logfile," %lu dihedrals\n",atom->ndihedrals); + char str[32]; + sprintf(str," %s dihedrals\n",BIGINT_FORMAT); + if (screen) fprintf(screen,str,atom->ndihedrals); + if (logfile) fprintf(logfile,str,atom->ndihedrals); } if (atom->nimpropers) { - if (screen) fprintf(screen," %lu impropers\n",atom->nimpropers); - if (logfile) fprintf(logfile," %lu impropers\n",atom->nimpropers); + char str[32]; + sprintf(str," %s impropers\n",BIGINT_FORMAT); + if (screen) fprintf(screen,str,atom->nimpropers); + if (logfile) fprintf(logfile,str,atom->nimpropers); } } @@ -455,6 +466,21 @@ void ReadRestart::header() version,universe->version); } delete [] version; + + // check lmptype.h sizes, error if different + + } else if (flag == SMALLINT) { + int size = read_int(); + if (size != sizeof(smallint)) + error->all("Smallint setting in lmptype.h is not compatible"); + } else if (flag == TAGINT) { + int size = read_int(); + if (size != sizeof(tagint)) + error->all("Tagint setting in lmptype.h is not compatible"); + } else if (flag == BIGINT) { + int size = read_int(); + if (size != sizeof(bigint)) + error->all("Bigint setting in lmptype.h is not compatible"); // reset unit_style only if different // so that timestep,neighbor-skin are not changed @@ -465,7 +491,9 @@ void ReadRestart::header() delete [] style; } else if (flag == NTIMESTEP) { - update->ntimestep = read_int(); + // placeholder until ntimestep is 8-bytes + bigint ntimestep = read_bigint(); + update->ntimestep = static_cast (ntimestep); // set dimension from restart file diff --git a/src/replicate.cpp b/src/replicate.cpp index 7c8fc5e68e..5ade979e61 100644 --- a/src/replicate.cpp +++ b/src/replicate.cpp @@ -124,23 +124,25 @@ void Replicate::command(int narg, char **arg) } atom->create_avec(old->atom_style,nstyles,keywords); - // check that new problem size will not be too large - // if N > 2^31, turn off tags for existing and new atoms - // if molecular, N/Nbonds/etc cannot be > 2^31 else tags/counts invalid - - double rep = nrep; - if (rep*old->natoms > MAXSMALLINT) atom->tag_enable = 0; + // check that new system will not be too large + // if molecular and N > MAXTAGINT, error + // if atomic and new N > MAXTAGINT, turn off tags for existing and new atoms + // new system cannot exceed MAXBIGINT + if (atom->molecular && (nrep*old->natoms < 0 || nrep*old->natoms > MAXTAGINT)) + error->all("Replicated molecular system atom IDs are too big"); + if (nrep*old->natoms < 0 || nrep*old->natoms > MAXTAGINT) + atom->tag_enable = 0; if (atom->tag_enable == 0) for (int i = 0; i < atom->nlocal; i++) atom->tag[i] = 0; - if (atom->molecular) { - if (rep*old->natoms > MAXBIGINT || rep*old->nbonds > MAXBIGINT || - rep*old->nangles > MAXBIGINT || rep*old->ndihedrals > MAXBIGINT || - rep*old->nimpropers > MAXBIGINT) - error->all("Too big a problem to replicate with molecular atom style"); - } + if (nrep*old->natoms < 0 || nrep*old->natoms > MAXBIGINT || + nrep*old->nbonds < 0 || nrep*old->nbonds > MAXBIGINT || + nrep*old->nangles < 0 || nrep*old->nangles > MAXBIGINT || + nrep*old->ndihedrals < 0 || nrep*old->ndihedrals > MAXBIGINT || + nrep*old->nimpropers < 0 || nrep*old->nimpropers > MAXBIGINT) + error->all("Replicated system is too big"); // assign atom and topology counts in new class from old one @@ -368,8 +370,10 @@ void Replicate::command(int narg, char **arg) MPI_Allreduce(&nblocal,&natoms,1,MPI_LMP_BIGINT,MPI_SUM,world); if (me == 0) { - if (screen) fprintf(screen," %lu atoms\n",natoms); - if (logfile) fprintf(logfile," %lu atoms\n",natoms); + char str[32]; + sprintf(str," %s atoms\n",BIGINT_FORMAT); + if (screen) fprintf(screen,str,natoms); + if (logfile) fprintf(logfile,str,natoms); } if (natoms != atom->natoms) @@ -377,20 +381,28 @@ void Replicate::command(int narg, char **arg) if (me == 0) { if (atom->nbonds) { - if (screen) fprintf(screen," %lu bonds\n",atom->nbonds); - if (logfile) fprintf(logfile," %lu bonds\n",atom->nbonds); + char str[32]; + sprintf(str," %s bonds\n",BIGINT_FORMAT); + if (screen) fprintf(screen,str,atom->nbonds); + if (logfile) fprintf(logfile,str,atom->nbonds); } if (atom->nangles) { - if (screen) fprintf(screen," %lu angles\n",atom->nangles); - if (logfile) fprintf(logfile," %lu angles\n",atom->nangles); + char str[32]; + sprintf(str," %s angles\n",BIGINT_FORMAT); + if (screen) fprintf(screen,str,atom->nangles); + if (logfile) fprintf(logfile,str,atom->nangles); } if (atom->ndihedrals) { - if (screen) fprintf(screen," %lu dihedrals\n",atom->ndihedrals); - if (logfile) fprintf(logfile," %lu dihedrals\n",atom->ndihedrals); + char str[32]; + sprintf(str," %s dihedrals\n",BIGINT_FORMAT); + if (screen) fprintf(screen,str,atom->ndihedrals); + if (logfile) fprintf(logfile,str,atom->ndihedrals); } if (atom->nimpropers) { - if (screen) fprintf(screen," %lu impropers\n",atom->nimpropers); - if (logfile) fprintf(logfile," %lu impropers\n",atom->nimpropers); + char str[32]; + sprintf(str," %s impropers\n",BIGINT_FORMAT); + if (screen) fprintf(screen,str,atom->nimpropers); + if (logfile) fprintf(logfile,str,atom->nimpropers); } } diff --git a/src/thermo.cpp b/src/thermo.cpp index 76af0c0d13..2c0dbe93fa 100644 --- a/src/thermo.cpp +++ b/src/thermo.cpp @@ -139,8 +139,13 @@ Thermo::Thermo(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) format_float_multi_def = (char *) "%14.4f"; format_int_one_def = (char *) "%8d"; format_int_multi_def = (char *) "%14d"; - format_bigint_one_def = (char *) "%8lu"; - format_bigint_multi_def = (char *) "%14lu"; + if (sizeof(bigint) == 8) { + format_bigint_one_def = (char *) "%8ld"; + format_bigint_multi_def = (char *) "%14ld"; + } else if (sizeof(bigint) == 4) { + format_bigint_one_def = (char *) "%8d"; + format_bigint_multi_def = (char *) "%14d"; + } format_float_user = NULL; format_int_user = NULL; format_bigint_user = NULL; @@ -354,6 +359,7 @@ bigint Thermo::lost_check() bigint ntotal; bigint nblocal = atom->nlocal; MPI_Allreduce(&nblocal,&ntotal,1,MPI_LMP_BIGINT,MPI_SUM,world); + if (ntotal < 0 || ntotal > MAXBIGINT) error->all("Too many total atoms"); if (ntotal == atom->natoms) return ntotal; // if not checking or already warned, just return @@ -364,15 +370,19 @@ bigint Thermo::lost_check() // error message if (lostflag == ERROR) { - char str[128]; - sprintf(str,"Lost atoms: original %lu current %lu",atom->natoms,ntotal); + char fstr[64],str[64]; + sprintf(fstr, + "Lost atoms: original %s current %s",BIGINT_FORMAT,BIGINT_FORMAT); + sprintf(str,fstr,atom->natoms,ntotal); error->all(str); } // warning message - char str[128]; - sprintf(str,"Lost atoms: original %lu current %lu",atom->natoms,ntotal); + char fstr[64],str[64]; + sprintf(fstr, + "Lost atoms: original %s current %s",BIGINT_FORMAT,BIGINT_FORMAT); + sprintf(str,fstr,atom->natoms,ntotal); if (me == 0) error->warning(str,0); lostbefore = 1; return ntotal; @@ -505,7 +515,10 @@ void Thermo::modify_params(int narg, char **arg) if (ptr == NULL) error->all("Thermo_modify int format does not contain d character"); *ptr = '\0'; - sprintf(format_bigint_user,"%s%s%s",format_int_user,"lu",ptr+1); + if (sizeof(bigint) == 8) + sprintf(format_bigint_user,"%s%s%s",format_int_user,"ld",ptr+1); + else if (sizeof(bigint) == 4) + sprintf(format_bigint_user,"%s%s%s",format_int_user,"d",ptr+1); *ptr = 'd'; } else if (strcmp(arg[iarg+1],"float") == 0) { if (format_float_user) delete [] format_float_user; diff --git a/src/thermo.h b/src/thermo.h index 526fcfa89f..d1f8b1149b 100644 --- a/src/thermo.h +++ b/src/thermo.h @@ -68,7 +68,7 @@ class Thermo : protected Pointers { // data used by routines that compute single values int ivalue; // integer value to print - double dvalue; // dvalue = double value to print + double dvalue; // double value to print bigint bivalue; // big integer value to print int ifield; // which field in thermo output is being computed int *field2index; // which compute,fix,variable calcs this field diff --git a/src/write_restart.cpp b/src/write_restart.cpp index 3608ddfad6..23df7fa261 100644 --- a/src/write_restart.cpp +++ b/src/write_restart.cpp @@ -42,7 +42,8 @@ using namespace LAMMPS_NS; // same as read_restart.cpp and tools/restart2data.cpp -enum{VERSION,UNITS,NTIMESTEP,DIMENSION,NPROCS,PROCGRID_0,PROCGRID_1,PROCGRID_2, +enum{VERSION,SMALLINT,TAGINT,BIGINT, + UNITS,NTIMESTEP,DIMENSION,NPROCS,PROCGRID_0,PROCGRID_1,PROCGRID_2, NEWTON_PAIR,NEWTON_BOND,XPERIODIC,YPERIODIC,ZPERIODIC, BOUNDARY_00,BOUNDARY_01,BOUNDARY_10,BOUNDARY_11,BOUNDARY_20,BOUNDARY_21, ATOM_STYLE,NATOMS,NTYPES, @@ -295,8 +296,13 @@ void WriteRestart::write(char *file) void WriteRestart::header() { write_char(VERSION,universe->version); + write_int(SMALLINT,sizeof(smallint)); + write_int(TAGINT,sizeof(tagint)); + write_int(BIGINT,sizeof(bigint)); write_char(UNITS,update->unit_style); - write_int(NTIMESTEP,update->ntimestep); + // placeholder until ntimestep is 8-byte + bigint ntimestep = update->ntimestep; + write_bigint(NTIMESTEP,ntimestep); write_int(DIMENSION,domain->dimension); write_int(NPROCS,nprocs); write_int(PROCGRID_0,comm->procgrid[0]);