From adcd46da55303428ba26ee1846ad12b577c8bc8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=BCtter?= Date: Wed, 6 Mar 2019 12:59:37 +0100 Subject: [PATCH 1/5] require an atom map for dynamical_matrix --- src/USER-PHONON/dynamical_matrix.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/USER-PHONON/dynamical_matrix.cpp b/src/USER-PHONON/dynamical_matrix.cpp index 372f4e4e31..c12bf6873e 100644 --- a/src/USER-PHONON/dynamical_matrix.cpp +++ b/src/USER-PHONON/dynamical_matrix.cpp @@ -138,6 +138,9 @@ void DynamicalMatrix::command(int narg, char **arg) else if (style == ESKM) options(narg-3,&arg[3]); //COME BACK else if (comm->me == 0 && screen) fprintf(screen,"Illegal Dynamical Matrix command\n"); + if (atom->map_style == 0) + error->all(FLERR,"Dynamical_matrix command requires an atom map, see atom_modify"); + // move atoms by 3-vector or specified variable(s) if (style == REGULAR) { From d30e69e87123c1c5f24d7ba4d488066b217d5bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=BCtter?= Date: Wed, 6 Mar 2019 13:28:44 +0100 Subject: [PATCH 2/5] fix writing binary dynmat file --- src/USER-PHONON/dynamical_matrix.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/USER-PHONON/dynamical_matrix.cpp b/src/USER-PHONON/dynamical_matrix.cpp index c12bf6873e..5b571213c7 100644 --- a/src/USER-PHONON/dynamical_matrix.cpp +++ b/src/USER-PHONON/dynamical_matrix.cpp @@ -337,7 +337,8 @@ void DynamicalMatrix::writeMatrix(double **dynmat) if (binaryflag && fp) { clearerr(fp); - fwrite(&dynmat[0], sizeof(double), 3 * dynlen, fp); + for (int i=0; i<3; i++) + fwrite(dynmat[i], sizeof(double), dynlen, fp); if (ferror(fp)) error->one(FLERR, "Error writing to binary file"); } From bb8398b22b966d617c4ce339081547026db4b8ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=BCtter?= Date: Wed, 6 Mar 2019 13:49:25 +0100 Subject: [PATCH 3/5] streamline writeMatrix function --- src/USER-PHONON/dynamical_matrix.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/USER-PHONON/dynamical_matrix.cpp b/src/USER-PHONON/dynamical_matrix.cpp index 5b571213c7..7b08e826a4 100644 --- a/src/USER-PHONON/dynamical_matrix.cpp +++ b/src/USER-PHONON/dynamical_matrix.cpp @@ -319,28 +319,24 @@ void DynamicalMatrix::calculateMatrix() void DynamicalMatrix::writeMatrix(double **dynmat) { - if (me != 0 || fp == NULL) return; + if (me != 0 || !fp) + return; - // print file comment lines - - if (!binaryflag && fp) { - clearerr(fp); + clearerr(fp); + if (binaryflag) { + for (int i=0; i<3; i++) + fwrite(dynmat[i], sizeof(double), dynlen, fp); + if (ferror(fp)) + error->one(FLERR, "Error writing to binary file"); + } else { for (int i = 0; i < 3; i++) { for (bigint j = 0; j < dynlen; j++) { if ((j+1)%3==0) fprintf(fp, "%4.8f\n", dynmat[i][j]); else fprintf(fp, "%4.8f ",dynmat[i][j]); } } - } - if (ferror(fp)) - error->one(FLERR,"Error writing to file"); - - if (binaryflag && fp) { - clearerr(fp); - for (int i=0; i<3; i++) - fwrite(dynmat[i], sizeof(double), dynlen, fp); if (ferror(fp)) - error->one(FLERR, "Error writing to binary file"); + error->one(FLERR,"Error writing to file"); } } From e8efa01006d574c44ca2e379f78eb7645c2132ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=BCtter?= Date: Wed, 6 Mar 2019 14:28:58 +0100 Subject: [PATCH 4/5] dynamical_matrix progress indicator --- src/USER-PHONON/dynamical_matrix.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/USER-PHONON/dynamical_matrix.cpp b/src/USER-PHONON/dynamical_matrix.cpp index 7b08e826a4..b4a676b4db 100644 --- a/src/USER-PHONON/dynamical_matrix.cpp +++ b/src/USER-PHONON/dynamical_matrix.cpp @@ -262,6 +262,7 @@ void DynamicalMatrix::calculateMatrix() if (comm->me == 0 && screen) fprintf(screen,"Calculating Dynamical Matrix...\n"); update->nsteps = 0; + int prog = 0; for (bigint i=1; i<=natoms; i++){ local_idx = atom->map(i); for (bigint alpha=0; alpha<3; alpha++){ @@ -300,7 +301,16 @@ void DynamicalMatrix::calculateMatrix() if (me == 0) writeMatrix(fdynmat); dynmat_clear(dynmat); + if (comm->me == 0 && screen) { + int p = 10 * i / natoms; + if (p > prog) { + prog = p; + fprintf(screen," %d%%",p*10); + fflush(screen); + } + } } + if (comm->me == 0 && screen) fprintf(screen,"\n"); for (int i=0; i < 3; i++) delete [] dynmat[i]; From 7fe1cceb7656351697f0b931b6cd7131d4706bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=BCtter?= Date: Thu, 7 Mar 2019 16:22:04 +0100 Subject: [PATCH 5/5] fix some leftover bigint conversions, groupmap construction --- src/USER-PHONON/dynamical_matrix.cpp | 46 ++++++++++++++++++---------- src/USER-PHONON/dynamical_matrix.h | 2 +- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/USER-PHONON/dynamical_matrix.cpp b/src/USER-PHONON/dynamical_matrix.cpp index b4a676b4db..d94bd11a80 100644 --- a/src/USER-PHONON/dynamical_matrix.cpp +++ b/src/USER-PHONON/dynamical_matrix.cpp @@ -243,7 +243,7 @@ void DynamicalMatrix::calculateMatrix() int nlocal = atom->nlocal; bigint natoms = atom->natoms; int *type = atom->type; - int *gm = groupmap; + bigint *gm = groupmap; double imass; // dynamical matrix element double *m = atom->mass; double **f = atom->f; @@ -259,21 +259,30 @@ void DynamicalMatrix::calculateMatrix() //initialize dynmat to all zeros dynmat_clear(dynmat); - if (comm->me == 0 && screen) fprintf(screen,"Calculating Dynamical Matrix...\n"); + if (comm->me == 0 && screen) { + fprintf(screen,"Calculating Dynamical Matrix ...\n"); + fprintf(screen," Total # of atoms = " BIGINT_FORMAT "\n", natoms); + fprintf(screen," Atoms in group = " BIGINT_FORMAT "\n", gcount); + fprintf(screen," Total dynamical matrix elements = " BIGINT_FORMAT "\n", (dynlen*dynlen) ); + } + + // emit dynlen rows of dimalpha*dynlen*dimbeta elements update->nsteps = 0; int prog = 0; for (bigint i=1; i<=natoms; i++){ local_idx = atom->map(i); + if (gm[i-1] < 0) + continue; for (bigint alpha=0; alpha<3; alpha++){ displace_atom(local_idx, alpha, 1); update_force(); for (bigint j=1; j<=natoms; j++){ local_jdx = atom->map(j); if (local_idx >= 0 && local_jdx >= 0 && local_jdx < nlocal - && gm[i-1] >= 0 && gm[j-1] >= 0){ + && gm[j-1] >= 0){ for (int beta=0; beta<3; beta++){ - dynmat[alpha][(gm[j-1])*3+beta] -= f[local_jdx][beta]; + dynmat[alpha][gm[j-1]*3+beta] -= f[local_jdx][beta]; } } } @@ -282,15 +291,15 @@ void DynamicalMatrix::calculateMatrix() for (bigint j=1; j<=natoms; j++){ local_jdx = atom->map(j); if (local_idx >= 0 && local_jdx >= 0 && local_jdx < nlocal - && gm[i-1] >= 0 && gm[j-1] >= 0){ + && gm[j-1] >= 0){ for (bigint beta=0; beta<3; beta++){ if (atom->rmass_flag == 1) imass = sqrt(m[local_idx] * m[local_jdx]); else imass = sqrt(m[type[local_idx]] * m[type[local_jdx]]); - dynmat[alpha][(gm[j-1])*3+beta] -= -f[local_jdx][beta]; - dynmat[alpha][(gm[j-1])*3+beta] /= (2 * del * imass); - dynmat[alpha][(gm[j-1])*3+beta] *= conversion; + dynmat[alpha][gm[j-1]*3+beta] -= -f[local_jdx][beta]; + dynmat[alpha][gm[j-1]*3+beta] /= (2 * del * imass); + dynmat[alpha][gm[j-1]*3+beta] *= conversion; } } } @@ -302,7 +311,7 @@ void DynamicalMatrix::calculateMatrix() writeMatrix(fdynmat); dynmat_clear(dynmat); if (comm->me == 0 && screen) { - int p = 10 * i / natoms; + int p = 10 * gm[i-1] / gcount; if (p > prog) { prog = p; fprintf(screen," %d%%",p*10); @@ -500,6 +509,7 @@ void DynamicalMatrix::convert_units(const char *style) void DynamicalMatrix::create_groupmap() { //Create a group map which maps atom order onto group + // groupmap[global atom index-1] = output column/row int local_idx; // local index int gid = 0; //group index @@ -508,7 +518,7 @@ void DynamicalMatrix::create_groupmap() bigint natoms = atom->natoms; int *recv = new int[comm->nprocs]; int *displs = new int[comm->nprocs]; - int *temp_groupmap = new int[natoms]; + bigint *temp_groupmap = new bigint[natoms]; //find number of local atoms in the group (final_gid) for (bigint i=1; i<=natoms; i++){ @@ -517,7 +527,7 @@ void DynamicalMatrix::create_groupmap() gid += 1; // gid at the end of loop is final_Gid } //create an array of length final_gid - int *sub_groupmap = new int[gid]; + bigint *sub_groupmap = new bigint[gid]; gid = 0; //create a map between global atom id and group atom id for each proc @@ -534,7 +544,7 @@ void DynamicalMatrix::create_groupmap() recv[i] = 0; } recv[comm->me] = gid; - MPI_Allreduce(recv,displs,4,MPI_INT,MPI_SUM,world); + MPI_Allreduce(recv,displs,comm->nprocs,MPI_INT,MPI_SUM,world); for (int i=0; inprocs; i++){ recv[i]=displs[i]; if (i>0) displs[i] = displs[i-1]+recv[i-1]; @@ -542,15 +552,17 @@ void DynamicalMatrix::create_groupmap() } //combine subgroup maps into total temporary groupmap - MPI_Allgatherv(sub_groupmap,gid,MPI_INT,temp_groupmap,recv,displs,MPI_INT,world); + MPI_Allgatherv(sub_groupmap,gid,MPI_LMP_BIGINT,temp_groupmap,recv,displs,MPI_LMP_BIGINT,world); std::sort(temp_groupmap,temp_groupmap+gcount); //populate member groupmap based on temp groupmap - for (bigint i=0; i