diff --git a/src/atom.h b/src/atom.h index 6c3f84d969..0cb05c7eb9 100644 --- a/src/atom.h +++ b/src/atom.h @@ -32,8 +32,8 @@ class Atom : protected Pointers { int tag_enable; // 0/1 if atom ID tags are defined int molecular; // 0 = atomic, 1 = molecular system + bigint nbonds,nangles,ndihedrals,nimpropers; int ntypes,nbondtypes,nangletypes,ndihedraltypes,nimpropertypes; - int nbonds,nangles,ndihedrals,nimpropers; int bond_per_atom,angle_per_atom,dihedral_per_atom,improper_per_atom; int extra_bond_per_atom; diff --git a/src/delete_bonds.cpp b/src/delete_bonds.cpp index fc4e2d04dc..424e39750a 100644 --- a/src/delete_bonds.cpp +++ b/src/delete_bonds.cpp @@ -339,30 +339,32 @@ void DeleteBonds::command(int narg, char **arg) if (remove_flag) { if (atom->avec->bonds_allow) { - int nbonds = 0; + bigint nbonds = 0; for (i = 0; i < nlocal; i++) nbonds += atom->num_bond[i]; - MPI_Allreduce(&nbonds,&atom->nbonds,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&nbonds,&atom->nbonds,1,MPI_UNSIGNED_LONG,MPI_SUM,world); if (force->newton_bond == 0) atom->nbonds /= 2; } if (atom->avec->angles_allow) { - int nangles = 0; + bigint nangles = 0; for (i = 0; i < nlocal; i++) nangles += atom->num_angle[i]; - MPI_Allreduce(&nangles,&atom->nangles,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&nangles,&atom->nangles,1,MPI_UNSIGNED_LONG,MPI_SUM,world); if (force->newton_bond == 0) atom->nangles /= 3; } if (atom->avec->dihedrals_allow) { - int ndihedrals = 0; + bigint ndihedrals = 0; for (i = 0; i < nlocal; i++) ndihedrals += atom->num_dihedral[i]; - MPI_Allreduce(&ndihedrals,&atom->ndihedrals,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&ndihedrals,&atom->ndihedrals, + 1,MPI_UNSIGNED_LONG,MPI_SUM,world); if (force->newton_bond == 0) atom->ndihedrals /= 4; } if (atom->avec->impropers_allow) { - int nimpropers = 0; + bigint nimpropers = 0; for (i = 0; i < nlocal; i++) nimpropers += atom->num_improper[i]; - MPI_Allreduce(&nimpropers,&atom->nimpropers,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&nimpropers,&atom->nimpropers, + 1,MPI_UNSIGNED_LONG,MPI_SUM,world); if (force->newton_bond == 0) atom->nimpropers /= 4; } @@ -370,11 +372,11 @@ void DeleteBonds::command(int narg, char **arg) // compute and print stats - int tmp; - int bond_on,bond_off; - int angle_on,angle_off; - int dihedral_on,dihedral_off; - int improper_on,improper_off; + bigint tmp; + bigint bond_on,bond_off; + bigint angle_on,angle_off; + bigint dihedral_on,dihedral_off; + bigint improper_on,improper_off; if (atom->avec->bonds_allow) { bond_on = bond_off = 0; @@ -382,9 +384,9 @@ void DeleteBonds::command(int narg, char **arg) for (m = 0; m < atom->num_bond[i]; m++) if (atom->bond_type[i][m] > 0) bond_on++; else bond_off++; - MPI_Allreduce(&bond_on,&tmp,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&bond_on,&tmp,1,MPI_UNSIGNED_LONG,MPI_SUM,world); bond_on = tmp; - MPI_Allreduce(&bond_off,&tmp,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&bond_off,&tmp,1,MPI_UNSIGNED_LONG,MPI_SUM,world); bond_off = tmp; if (force->newton_bond == 0) { bond_on /= 2; @@ -398,9 +400,9 @@ void DeleteBonds::command(int narg, char **arg) for (m = 0; m < atom->num_angle[i]; m++) if (atom->angle_type[i][m] > 0) angle_on++; else angle_off++; - MPI_Allreduce(&angle_on,&tmp,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&angle_on,&tmp,1,MPI_UNSIGNED_LONG,MPI_SUM,world); angle_on = tmp; - MPI_Allreduce(&angle_off,&tmp,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&angle_off,&tmp,1,MPI_UNSIGNED_LONG,MPI_SUM,world); angle_off = tmp; if (force->newton_bond == 0) { angle_on /= 3; @@ -414,9 +416,9 @@ void DeleteBonds::command(int narg, char **arg) for (m = 0; m < atom->num_dihedral[i]; m++) if (atom->dihedral_type[i][m] > 0) dihedral_on++; else dihedral_off++; - MPI_Allreduce(&dihedral_on,&tmp,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&dihedral_on,&tmp,1,MPI_UNSIGNED_LONG,MPI_SUM,world); dihedral_on = tmp; - MPI_Allreduce(&dihedral_off,&tmp,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&dihedral_off,&tmp,1,MPI_UNSIGNED_LONG,MPI_SUM,world); dihedral_off = tmp; if (force->newton_bond == 0) { dihedral_on /= 4; @@ -430,9 +432,9 @@ void DeleteBonds::command(int narg, char **arg) for (m = 0; m < atom->num_improper[i]; m++) if (atom->improper_type[i][m] > 0) improper_on++; else improper_off++; - MPI_Allreduce(&improper_on,&tmp,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&improper_on,&tmp,1,MPI_UNSIGNED_LONG,MPI_SUM,world); improper_on = tmp; - MPI_Allreduce(&improper_off,&tmp,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&improper_off,&tmp,1,MPI_UNSIGNED_LONG,MPI_SUM,world); improper_off = tmp; if (force->newton_bond == 0) { improper_on /= 4; @@ -443,30 +445,32 @@ void DeleteBonds::command(int narg, char **arg) if (comm->me == 0) { if (screen) { if (atom->avec->bonds_allow) - fprintf(screen," %d total bonds, %d turned on, %d turned off\n", + 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," %d total angles, %d turned on, %d turned off\n", + 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," %d total dihedrals, %d turned on, %d turned off\n", + 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," %d total impropers, %d turned on, %d turned off\n", + fprintf(screen," %lu total impropers, %lu turned on, %lu turned off\n", atom->nimpropers,improper_on,improper_off); } if (logfile) { if (atom->avec->bonds_allow) - fprintf(logfile," %d total bonds, %d turned on, %d turned off\n", + 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," %d total angles, %d turned on, %d turned off\n", + 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," %d total dihedrals, %d turned on, %d turned off\n", + 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," %d total impropers, %d turned on, %d turned off\n", + fprintf(logfile," %lu total impropers, %lu turned on, " + "%lu turned off\n", atom->nimpropers,improper_on,improper_off); } } diff --git a/src/read_data.cpp b/src/read_data.cpp index fb4d3efe90..1d960ef41d 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -337,10 +337,10 @@ 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,"%d",&atom->nbonds); - else if (strstr(line,"angles")) sscanf(line,"%d",&atom->nangles); - else if (strstr(line,"dihedrals")) sscanf(line,"%d",&atom->ndihedrals); - else if (strstr(line,"impropers")) sscanf(line,"%d",&atom->nimpropers); + 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); else if (strstr(line,"atom types")) sscanf(line,"%d",&atom->ntypes); else if (strstr(line,"bond types")) sscanf(line,"%d",&atom->nbondtypes); @@ -434,12 +434,12 @@ void ReadData::atoms() // check that all atoms were assigned correctly - double tmp = atom->nlocal; - MPI_Allreduce(&tmp,&natoms,1,MPI_DOUBLE,MPI_SUM,world); + bigint tmp = atom->nlocal; + MPI_Allreduce(&tmp,&natoms,1,MPI_UNSIGNED_LONG,MPI_SUM,world); if (me == 0) { - if (screen) fprintf(screen," %.15g atoms\n",natoms); - if (logfile) fprintf(logfile," %.15g atoms\n",natoms); + if (screen) fprintf(screen," %lu atoms\n",natoms); + if (logfile) fprintf(logfile," %lu atoms\n",natoms); } if (natoms != atom->natoms) error->all("Did not assign all atoms correctly"); @@ -529,8 +529,8 @@ void ReadData::velocities() } if (me == 0) { - if (screen) fprintf(screen," %.15g velocities\n",natoms); - if (logfile) fprintf(logfile," %.15g velocities\n",natoms); + if (screen) fprintf(screen," %lu velocities\n",natoms); + if (logfile) fprintf(logfile," %lu velocities\n",natoms); } } @@ -540,9 +540,11 @@ void ReadData::bonds() { int i,m,nchunk; - int nread = 0; - while (nread < atom->nbonds) { - nchunk = MIN(atom->nbonds-nread,CHUNK); + bigint nread = 0; + bigint nbonds = atom->nbonds; + + while (nread < nbonds) { + nchunk = MIN(nbonds-nread,CHUNK); if (me == 0) { char *eof; m = 0; @@ -563,17 +565,16 @@ void ReadData::bonds() // check that bonds were assigned correctly int nlocal = atom->nlocal; - - int sum; - int n = 0; + bigint sum; + bigint n = 0; for (i = 0; i < nlocal; i++) n += atom->num_bond[i]; - MPI_Allreduce(&n,&sum,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&n,&sum,1,MPI_UNSIGNED_LONG,MPI_SUM,world); int factor = 1; if (!force->newton_bond) factor = 2; if (me == 0) { - if (screen) fprintf(screen," %d bonds\n",sum/factor); - if (logfile) fprintf(logfile," %d bonds\n",sum/factor); + if (screen) fprintf(screen," %lu bonds\n",sum/factor); + if (logfile) fprintf(logfile," %lu bonds\n",sum/factor); } if (sum != factor*atom->nbonds) error->all("Bonds assigned incorrectly"); } @@ -584,9 +585,11 @@ void ReadData::angles() { int i,m,nchunk; - int nread = 0; - while (nread < atom->nangles) { - nchunk = MIN(atom->nangles-nread,CHUNK); + bigint nread = 0; + bigint nangles = atom->nangles; + + while (nread < nangles) { + nchunk = MIN(nangles-nread,CHUNK); if (me == 0) { char *eof; m = 0; @@ -604,20 +607,19 @@ void ReadData::angles() nread += nchunk; } - // check that angles were assigned correctly + // check that ang int nlocal = atom->nlocal; - - int sum; - int n = 0; + bigint sum; + bigint n = 0; for (i = 0; i < nlocal; i++) n += atom->num_angle[i]; - MPI_Allreduce(&n,&sum,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&n,&sum,1,MPI_UNSIGNED_LONG,MPI_SUM,world); int factor = 1; if (!force->newton_bond) factor = 3; if (me == 0) { - if (screen) fprintf(screen," %d angles\n",sum/factor); - if (logfile) fprintf(logfile," %d angles\n",sum/factor); + if (screen) fprintf(screen," %lu angles\n",sum/factor); + if (logfile) fprintf(logfile," %lu angles\n",sum/factor); } if (sum != factor*atom->nangles) error->all("Angles assigned incorrectly"); } @@ -628,9 +630,11 @@ void ReadData::dihedrals() { int i,m,nchunk; - int nread = 0; - while (nread < atom->ndihedrals) { - nchunk = MIN(atom->ndihedrals-nread,CHUNK); + bigint nread = 0; + bigint ndihedrals = atom->ndihedrals; + + while (nread < ndihedrals) { + nchunk = MIN(ndihedrals-nread,CHUNK); if (me == 0) { char *eof; m = 0; @@ -651,17 +655,16 @@ void ReadData::dihedrals() // check that dihedrals were assigned correctly int nlocal = atom->nlocal; - - int sum; - int n = 0; + bigint sum; + bigint n = 0; for (i = 0; i < nlocal; i++) n += atom->num_dihedral[i]; - MPI_Allreduce(&n,&sum,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&n,&sum,1,MPI_UNSIGNED_LONG,MPI_SUM,world); int factor = 1; if (!force->newton_bond) factor = 4; if (me == 0) { - if (screen) fprintf(screen," %d dihedrals\n",sum/factor); - if (logfile) fprintf(logfile," %d dihedrals\n",sum/factor); + if (screen) fprintf(screen," %lu dihedrals\n",sum/factor); + if (logfile) fprintf(logfile," %lu dihedrals\n",sum/factor); } if (sum != factor*atom->ndihedrals) error->all("Dihedrals assigned incorrectly"); @@ -673,9 +676,11 @@ void ReadData::impropers() { int i,m,nchunk; - int nread = 0; - while (nread < atom->nimpropers) { - nchunk = MIN(atom->nimpropers-nread,CHUNK); + bigint nread = 0; + bigint nimpropers = atom->nimpropers; + + while (nread < nimpropers) { + nchunk = MIN(nread,CHUNK); if (me == 0) { char *eof; m = 0; @@ -696,17 +701,16 @@ void ReadData::impropers() // check that impropers were assigned correctly int nlocal = atom->nlocal; - - int sum; - int n = 0; + bigint sum; + bigint n = 0; for (i = 0; i < nlocal; i++) n += atom->num_improper[i]; - MPI_Allreduce(&n,&sum,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&n,&sum,1,MPI_UNSIGNED_LONG,MPI_SUM,world); int factor = 1; if (!force->newton_bond) factor = 4; if (me == 0) { - if (screen) fprintf(screen," %d impropers\n",sum/factor); - if (logfile) fprintf(logfile," %d impropers\n",sum/factor); + if (screen) fprintf(screen," %lu impropers\n",sum/factor); + if (logfile) fprintf(logfile," %lu impropers\n",sum/factor); } if (sum != factor*atom->nimpropers) error->all("Impropers assigned incorrectly"); @@ -972,6 +976,9 @@ void ReadData::scan(int &bond_per_atom, int &angle_per_atom, int i,tmp1,tmp2,atom1,atom2,atom3,atom4; char *eof; + if (atom->natoms > MAXINT32) + error->all("Molecular data file has too many atoms"); + int natoms = static_cast (atom->natoms); bond_per_atom = angle_per_atom = dihedral_per_atom = improper_per_atom = 0; diff --git a/src/read_restart.cpp b/src/read_restart.cpp index 1b759d8840..9e0bd656b1 100644 --- a/src/read_restart.cpp +++ b/src/read_restart.cpp @@ -304,20 +304,20 @@ void ReadRestart::command(int narg, char **arg) if (me == 0) { if (atom->nbonds) { - if (screen) fprintf(screen," %d bonds\n",atom->nbonds); - if (logfile) fprintf(logfile," %d bonds\n",atom->nbonds); + if (screen) fprintf(screen," %lu bonds\n",atom->nbonds); + if (logfile) fprintf(logfile," %lu bonds\n",atom->nbonds); } if (atom->nangles) { - if (screen) fprintf(screen," %d angles\n",atom->nangles); - if (logfile) fprintf(logfile," %d angles\n",atom->nangles); + if (screen) fprintf(screen," %lu angles\n",atom->nangles); + if (logfile) fprintf(logfile," %lu angles\n",atom->nangles); } if (atom->ndihedrals) { - if (screen) fprintf(screen," %d dihedrals\n",atom->ndihedrals); - if (logfile) fprintf(logfile," %d dihedrals\n",atom->ndihedrals); + if (screen) fprintf(screen," %lu dihedrals\n",atom->ndihedrals); + if (logfile) fprintf(logfile," %lu dihedrals\n",atom->ndihedrals); } if (atom->nimpropers) { - if (screen) fprintf(screen," %d impropers\n",atom->nimpropers); - if (logfile) fprintf(logfile," %d impropers\n",atom->nimpropers); + if (screen) fprintf(screen," %lu impropers\n",atom->nimpropers); + if (logfile) fprintf(logfile," %lu impropers\n",atom->nimpropers); } } @@ -599,25 +599,25 @@ void ReadRestart::header() } else if (flag == NTYPES) { atom->ntypes = read_int(); } else if (flag == NBONDS) { - atom->nbonds = read_int(); + atom->nbonds = read_bigint(); } else if (flag == NBONDTYPES) { atom->nbondtypes = read_int(); } else if (flag == BOND_PER_ATOM) { atom->bond_per_atom = read_int(); } else if (flag == NANGLES) { - atom->nangles = read_int(); + atom->nangles = read_bigint(); } else if (flag == NANGLETYPES) { atom->nangletypes = read_int(); } else if (flag == ANGLE_PER_ATOM) { atom->angle_per_atom = read_int(); } else if (flag == NDIHEDRALS) { - atom->ndihedrals = read_int(); + atom->ndihedrals = read_bigint(); } else if (flag == NDIHEDRALTYPES) { atom->ndihedraltypes = read_int(); } else if (flag == DIHEDRAL_PER_ATOM) { atom->dihedral_per_atom = read_int(); } else if (flag == NIMPROPERS) { - atom->nimpropers = read_int(); + atom->nimpropers = read_bigint(); } else if (flag == NIMPROPERTYPES) { atom->nimpropertypes = read_int(); } else if (flag == IMPROPER_PER_ATOM) { diff --git a/src/write_restart.cpp b/src/write_restart.cpp index c67e88271e..44e3de2637 100644 --- a/src/write_restart.cpp +++ b/src/write_restart.cpp @@ -334,16 +334,16 @@ void WriteRestart::header() write_bigint(NATOMS,natoms); write_int(NTYPES,atom->ntypes); - write_int(NBONDS,atom->nbonds); + write_bigint(NBONDS,atom->nbonds); write_int(NBONDTYPES,atom->nbondtypes); write_int(BOND_PER_ATOM,atom->bond_per_atom); - write_int(NANGLES,atom->nangles); + write_bigint(NANGLES,atom->nangles); write_int(NANGLETYPES,atom->nangletypes); write_int(ANGLE_PER_ATOM,atom->angle_per_atom); - write_int(NDIHEDRALS,atom->ndihedrals); + write_bigint(NDIHEDRALS,atom->ndihedrals); write_int(NDIHEDRALTYPES,atom->ndihedraltypes); write_int(DIHEDRAL_PER_ATOM,atom->dihedral_per_atom); - write_int(NIMPROPERS,atom->nimpropers); + write_bigint(NIMPROPERS,atom->nimpropers); write_int(NIMPROPERTYPES,atom->nimpropertypes); write_int(IMPROPER_PER_ATOM,atom->improper_per_atom);