@@ -205,7 +205,7 @@ DumpNC::DumpNC(LAMMPS *lmp, int narg, char **arg) :
205
205
206
206
DumpNC::~DumpNC ()
207
207
{
208
- if (me == 0 && singlefile_opened)
208
+ if (filewriter && singlefile_opened)
209
209
NCERR ( nc_close (ncid) );
210
210
211
211
if (rbuf) memory->destroy (rbuf);
@@ -247,7 +247,7 @@ void DumpNC::openfile()
247
247
// get total number of atoms
248
248
ntotalgr = group->count (igroup);
249
249
250
- if (me == 0 ) {
250
+ if (filewriter ) {
251
251
if (append_flag && access (filename, F_OK) != -1 ) {
252
252
// Fixme! Perform checks if dimensions and variables conform with
253
253
// data structure standard.
@@ -532,14 +532,76 @@ void DumpNC::openfile()
532
532
533
533
/* ---------------------------------------------------------------------- */
534
534
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
+
535
597
void DumpNC::write_header (bigint n)
536
598
{
537
599
size_t start[2 ];
538
600
539
601
start[0 ] = framei;
540
602
start[1 ] = 0 ;
541
603
542
- if (me == 0 ) {
604
+ if (filewriter ) {
543
605
size_t count[2 ];
544
606
double time , cell_origin[3 ], cell_lengths[3 ], cell_angles[3 ];
545
607
@@ -590,49 +652,6 @@ void DumpNC::write_header(bigint n)
590
652
cell_angles) );
591
653
}
592
654
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
-
636
655
ndata = n;
637
656
blocki = 0 ;
638
657
}
0 commit comments