Skip to content

Commit ccfd6f5

Browse files
author
Lars Pastewka
committed
Fixed regression: Moved writing of global properties (such as computes or variables) from DumpNC::write_header to DumpNC::write. Reason: write_header is only called on a single process while write is called on all processes. This behavior was introduced into LAMMPS 2 Jun 2012, which broke the NetCDF dump style.
1 parent e16dca4 commit ccfd6f5

File tree

2 files changed

+70
-47
lines changed

2 files changed

+70
-47
lines changed

dump_nc.cpp

+65-46
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ DumpNC::DumpNC(LAMMPS *lmp, int narg, char **arg) :
205205

206206
DumpNC::~DumpNC()
207207
{
208-
if (me == 0 && singlefile_opened)
208+
if (filewriter && singlefile_opened)
209209
NCERR( nc_close(ncid) );
210210

211211
if (rbuf) memory->destroy(rbuf);
@@ -247,7 +247,7 @@ void DumpNC::openfile()
247247
// get total number of atoms
248248
ntotalgr = group->count(igroup);
249249

250-
if (me == 0) {
250+
if (filewriter) {
251251
if (append_flag && access(filename, F_OK) != -1) {
252252
// Fixme! Perform checks if dimensions and variables conform with
253253
// data structure standard.
@@ -532,14 +532,76 @@ void DumpNC::openfile()
532532

533533
/* ---------------------------------------------------------------------- */
534534

535+
void DumpNC::write()
536+
{
537+
// need to write per-frame (global) properties here since they may come
538+
// from computes. write_header below is only called from the writing
539+
// processes, but modify->compute[j]->compute_* must be called from all
540+
// processes.
541+
542+
size_t start[2];
543+
544+
start[0] = framei;
545+
start[1] = 0;
546+
547+
for (int i = 0; i < n_perframe; i++) {
548+
549+
if (perframe[i].type == THIS_IS_A_BIGINT) {
550+
bigint data;
551+
(this->*perframe[i].compute)((void*) &data);
552+
553+
if (filewriter)
554+
#if defined(LAMMPS_SMALLBIG) || defined(LAMMPS_BIGBIG)
555+
NCERR( nc_put_var1_long(ncid, perframe[i].var, start, &data) );
556+
#else
557+
NCERR( nc_put_var1_int(ncid, perframe[i].var, start, &data) );
558+
#endif
559+
}
560+
else {
561+
double data;
562+
int j = perframe[i].index;
563+
int idim = perframe[i].dim;
564+
565+
if (perframe[i].type == THIS_IS_A_COMPUTE) {
566+
if (idim >= 0) {
567+
modify->compute[j]->compute_vector();
568+
data = modify->compute[j]->vector[idim];
569+
}
570+
else
571+
data = modify->compute[j]->compute_scalar();
572+
}
573+
else if (perframe[i].type == THIS_IS_A_FIX) {
574+
if (idim >= 0) {
575+
data = modify->fix[j]->compute_vector(idim);
576+
}
577+
else
578+
data = modify->fix[j]->compute_scalar();
579+
}
580+
else if (perframe[i].type == THIS_IS_A_VARIABLE) {
581+
j = input->variable->find(perframe[i].id);
582+
data = input->variable->compute_equal(j);
583+
}
584+
585+
if (filewriter)
586+
NCERR( nc_put_var1_double(ncid, perframe[i].var, start, &data) );
587+
}
588+
}
589+
590+
// call write of superclass
591+
592+
Dump::write();
593+
}
594+
595+
/* ---------------------------------------------------------------------- */
596+
535597
void DumpNC::write_header(bigint n)
536598
{
537599
size_t start[2];
538600

539601
start[0] = framei;
540602
start[1] = 0;
541603

542-
if (me == 0) {
604+
if (filewriter) {
543605
size_t count[2];
544606
double time, cell_origin[3], cell_lengths[3], cell_angles[3];
545607

@@ -590,49 +652,6 @@ void DumpNC::write_header(bigint n)
590652
cell_angles) );
591653
}
592654

593-
for (int i = 0; i < n_perframe; i++) {
594-
595-
if (perframe[i].type == THIS_IS_A_BIGINT) {
596-
bigint data;
597-
(this->*perframe[i].compute)((void*) &data);
598-
599-
if (me == 0)
600-
#if defined(LAMMPS_SMALLBIG) || defined(LAMMPS_BIGBIG)
601-
NCERR( nc_put_var1_long(ncid, perframe[i].var, start, &data) );
602-
#else
603-
NCERR( nc_put_var1_int(ncid, perframe[i].var, start, &data) );
604-
#endif
605-
}
606-
else {
607-
double data;
608-
int j = perframe[i].index;
609-
int idim = perframe[i].dim;
610-
611-
if (perframe[i].type == THIS_IS_A_COMPUTE) {
612-
if (idim >= 0) {
613-
modify->compute[j]->compute_vector();
614-
data = modify->compute[j]->vector[idim];
615-
}
616-
else
617-
data = modify->compute[j]->compute_scalar();
618-
}
619-
else if (perframe[i].type == THIS_IS_A_FIX) {
620-
if (idim >= 0) {
621-
data = modify->fix[j]->compute_vector(idim);
622-
}
623-
else
624-
data = modify->fix[j]->compute_scalar();
625-
}
626-
else if (perframe[i].type == THIS_IS_A_VARIABLE) {
627-
j = input->variable->find(perframe[i].id);
628-
data = input->variable->compute_equal(j);
629-
}
630-
631-
if (me == 0)
632-
NCERR( nc_put_var1_double(ncid, perframe[i].var, start, &data) );
633-
}
634-
}
635-
636655
ndata = n;
637656
blocki = 0;
638657
}

dump_nc.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ const int NC_FIELD_NAME_MAX = 100;
2929
class DumpNC : public DumpCustom {
3030
public:
3131
DumpNC(class LAMMPS *, int, char **);
32-
~DumpNC();
32+
virtual ~DumpNC();
33+
virtual void write();
3334

3435
private:
3536
// per-atoms quantities (positions, velocities, etc.)
@@ -54,6 +55,9 @@ class DumpNC : public DumpCustom {
5455
funcptr_t compute; // compute function
5556
int dim; // dimension
5657
char id[NC_FIELD_NAME_MAX]; // variable id
58+
59+
bigint bigint_data; // actual data
60+
double double_data; // actual data
5761
};
5862

5963
int framei; // current frame index

0 commit comments

Comments
 (0)