40 #define access(PATH,MODE) _access(PATH,00) 43 #if defined(WIN32) && !defined(__CYGWIN__) 44 #define PATHSEPSTR "\\" 45 #define MKDIR(X) mkdir(X) 47 #define PATHSEPSTR "/" 48 #define MKDIR(X) mkdir(X,0777) 51 #define NAMD_open NAMD_open64 52 #define NAMD_write NAMD_write64 53 #define NAMD_close NAMD_close64 56 #define O_LARGEFILE 0x0 58 #define MIN_DEBUG_LEVEL 3 68 while ( (fd = _open(fname, O_WRONLY|O_CREAT|O_EXCL|O_BINARY|
O_LARGEFILE,_S_IREAD|_S_IWRITE)) < 0) {
71 while ( (fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC|
O_LARGEFILE,
73 while ( (fd = open(fname, O_WRONLY|O_CREAT|O_EXCL|
O_LARGEFILE,
75 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) {
77 if ( errno != EINTR ) {
79 sprintf(errmsg,
"Unable to open binary file %s", fname);
88 void NAMD_write(
int fd,
const char *buf,
size_t count,
const char *errmsg=
"NAMD_write64") {
89 double firsttime = 0.;
91 #if defined(WIN32) && !defined(__CYGWIN__) 92 long retval = _write(fd,buf,count);
94 ssize_t retval = write(fd,buf,count);
96 if ( retval < 0 && errno == EINTR ) retval = 0;
97 if ( retval < 0 && errno == ENOMEM ) {
98 if ( firsttime == 0. ) firsttime = CmiWallTimer();
99 if ( (CmiWallTimer() - firsttime) < 300. ) retval = 0;
102 if ( retval > count )
NAMD_bug(
"extra bytes written in NAMD_write64()");
106 if ( firsttime != 0. ) {
107 iout <<
iWARN << errmsg <<
": NAMD_write64() retried for " << (CmiWallTimer() - firsttime) <<
" seconds.\n" <<
endi;
114 while ( _close(fd) ) {
116 while ( close(fd) ) {
118 if ( errno != EINTR ) {
120 sprintf(errmsg,
"Error on closing file %s", fname);
127 #define seek_dcdfile NAMD_seek 130 #define namdMyNode Node::Object() 131 #define simParams simParameters 136 unitcell[0] = unitcell[2] = unitcell[5] = 0.0;
137 unitcell[1] = unitcell[3] = unitcell[4] = 0.0;
143 unitcell[0] = (lattice->
a_p()) ? a.
length() : 0.0;
144 unitcell[2] = (lattice->
b_p()) ? b.
length() : 0.0;
145 unitcell[5] = (lattice->
c_p()) ? c.
length() : 0.0;
146 double cosAB = (lattice->
a_p() && lattice->
b_p() ) ?
147 (a*b)/(unitcell[0]*unitcell[2]) : 0.0;
148 double cosAC = (lattice->
a_p() && lattice->
c_p() ) ?
149 (a*c)/(unitcell[0]*unitcell[5]) : 0.0;
150 double cosBC = (lattice->
b_p() && lattice->
c_p() ) ?
151 (b*c)/(unitcell[2]*unitcell[5]) : 0.0;
152 if (cosAB > 1.0) cosAB = 1.0;
else if (cosAB < -1.0) cosAB = -1.0;
153 if (cosAC > 1.0) cosAC = 1.0;
else if (cosAC < -1.0) cosAC = -1.0;
154 if (cosBC > 1.0) cosBC = 1.0;
else if (cosBC < -1.0) cosBC = -1.0;
189 if(
simParams->benchTimestep)
return std::make_pair(0,0);
191 int positionsNeeded = 0;
192 uint16 dcdSelectionTag = 0;
193 if ( timestep >= 0 ) {
197 ((timestep %
simParams->dcdFrequency) == 0) )
198 { positionsNeeded |= 1; }
206 for(
int index=0; index<16;++index)
210 if(frequency && (timestep % frequency) == 0)
214 positionsNeeded |= 4; dcdSelectionTag = tag;
220 ((timestep %
simParams->restartFrequency) == 0) )
221 { positionsNeeded |= 2; }
225 ( ((timestep %
simParams->IMDfreq) == 0) ||
226 (timestep ==
simParams->firstTimestep) ) &&
228 && (
simParams->IMDsendsettings.fcoords_switch == 1))) )
229 { positionsNeeded |= 1; }
237 positionsNeeded |= 2;
239 return std::make_pair(positionsNeeded,dcdSelectionTag);
242 template <
class xVector,
class xDone>
248 const int wrapNearest =
simParams->wrapNearest;
253 #ifndef MEM_OPT_VERSION 255 for ( i = 0; i < n; ++i ) {
260 for ( i = 0; i < n; ++i ) {
261 if ( ! wrapAll && ! molecule->
is_water(i) )
continue;
265 Vector trans = ( wrapNearest ?
269 coor[i] = coor[i] + con[ci];
276 template <
class xVector,
class xDone>
282 const int wrapNearest =
simParams->wrapNearest;
287 #ifndef MEM_OPT_VERSION 289 for ( i = 0; i < n; ++i ) {
296 con[dcdci] += coor[i];
298 for ( i = 0; i < n; ++i ) {
300 if ( ! wrapAll && ! molecule->
is_water(molIndex) )
continue;
303 if ( ci == molIndex ) {
305 Vector trans = ( wrapNearest ?
310 coor[i] = coor[i] + con[dcdci];
339 double coor_wrapped = 0;
340 float fcoor_wrapped = 0;
342 if ( timestep >= 0 ) {
346 ((timestep %
simParams->dcdFrequency) == 0) )
349 output_dcdfile(timestep, n, fcoor,
350 simParams->dcdUnitCell ? &lattice : NULL, 0);
356 bool needCleanup =
false;
358 for(
int index=0; index<16;++index)
363 if(frequency>0 && (timestep % frequency) == 0)
366 int dcdSelectionNpoints = n;
372 dcdSelectionNpoints = size;
373 dcdSelectionFcoor =
new FloatVector[dcdSelectionNpoints];
375 for(
int i=0; i<n ;i++)
379 dcdSelectionFcoor[offset] = fcoor[i];
384 dcdSelectionFcoor = fcoor;
387 output_dcdfile(timestep, dcdSelectionNpoints, dcdSelectionFcoor,
388 simParams->dcdUnitCell ? &lattice : NULL, tag);
390 delete [] dcdSelectionFcoor;
398 ((timestep %
simParams->restartFrequency) == 0) )
400 iout <<
"WRITING COORDINATES TO RESTART FILE AT STEP " 401 << timestep <<
"\n" <<
endi;
403 output_restart_coordinates(coor, n, timestep);
404 iout <<
"FINISHED WRITING RESTART COORDINATES\n" <<
endi;
410 ( ((timestep %
simParams->IMDfreq) == 0) ||
411 (timestep ==
simParams->firstTimestep) ) )
415 && (
simParams->IMDsendsettings.box_switch == 1))
418 #ifdef NODEGROUP_FORCE_REGISTER 420 CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
421 imd = cpdata.ckLocalBranch()->imd;
429 IMDBox box = {(float)lattice.
a().
x, (float)lattice.
a().
y, (float)lattice.
a().
z,
430 (float)lattice.
b().
x, (float)lattice.
b().
y, (float)lattice.
b().
z,
431 (float)lattice.
c().
x, (float)lattice.
c().
y, (float)lattice.
c().
z};
433 if (imd != NULL) imd->
gather_box(timestep, &box);
437 && (
simParams->IMDsendsettings.fcoords_switch == 1)))
440 #ifdef NODEGROUP_FORCE_REGISTER 442 CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
443 imd = cpdata.ckLocalBranch()->imd;
451 && (
simParams->IMDsendsettings.wrap_switch == 1)))
473 iout <<
"WRITING COORDINATES TO OUTPUT FILE AT STEP " 474 << realstep <<
"\n" <<
endi;
477 output_final_coordinates(coor, n, realstep);
485 ? &lattice : NULL, 0);
488 for(
int dcdSelectionIndex=0; dcdSelectionIndex<16;++dcdSelectionIndex)
492 if(dcdSelectionFrequency)
495 ? &lattice : NULL, dcdSelectionTag);
508 int velocitiesNeeded = 0;
510 if ( timestep >= 0 ) {
514 ((timestep %
simParams->velDcdFrequency) == 0) )
515 { velocitiesNeeded |= 1; }
519 ((timestep %
simParams->restartFrequency) == 0) )
520 { velocitiesNeeded |= 2; }
524 ( ((timestep %
simParams->IMDfreq) == 0) ||
525 (timestep ==
simParams->firstTimestep) ) &&
527 && (
simParams->IMDsendsettings.velocities_switch == 1)) )
528 { velocitiesNeeded |= 1; }
535 velocitiesNeeded |= 2;
538 return velocitiesNeeded;
545 if ( timestep >= 0 ) {
549 ((timestep %
simParams->velDcdFrequency) == 0) )
551 output_veldcdfile(timestep, n, fvel);
556 ((timestep %
simParams->restartFrequency) == 0) )
558 iout <<
"WRITING VELOCITIES TO RESTART FILE AT STEP " 559 << timestep <<
"\n" <<
endi;
560 output_restart_velocities(timestep, n, vel);
561 iout <<
"FINISHED WRITING RESTART VELOCITIES\n" <<
endi;
567 ( ((timestep %
simParams->IMDfreq) == 0) ||
568 (timestep ==
simParams->firstTimestep) ) &&
570 && (
simParams->IMDsendsettings.velocities_switch == 1)) )
573 #ifdef NODEGROUP_FORCE_REGISTER 575 CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
576 imd = cpdata.ckLocalBranch()->imd;
596 iout <<
"WRITING VELOCITIES TO OUTPUT FILE AT STEP " 597 << realstep <<
"\n" <<
endi;
599 output_final_velocities(realstep, n, vel);
618 int forcesNeeded = 0;
620 if ( timestep >= 0 ) {
624 ((timestep %
simParams->forceDcdFrequency) == 0) )
625 { forcesNeeded |= 1; }
629 ( ((timestep %
simParams->IMDfreq) == 0) ||
630 (timestep ==
simParams->firstTimestep) ) &&
632 && (
simParams->IMDsendsettings.forces_switch == 1))) )
633 { forcesNeeded |= 1; }
650 if ( timestep >= 0 ) {
654 ((timestep %
simParams->forceDcdFrequency) == 0) )
656 output_forcedcdfile(timestep, n, ffrc);
661 ( ((timestep %
simParams->IMDfreq) == 0) ||
662 (timestep ==
simParams->firstTimestep) ) &&
664 && (
simParams->IMDsendsettings.forces_switch == 1))) )
667 #ifdef NODEGROUP_FORCE_REGISTER 669 CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
670 imd = cpdata.ckLocalBranch()->imd;
686 iout <<
"WRITING FORCES TO OUTPUT FILE AT STEP " 687 << realstep <<
"\n" <<
endi;
689 output_forces(realstep, n, frc);
711 void Output::output_restart_coordinates(
Vector *coor,
int n,
int timestep)
715 char timestepstr[20];
717 int baselen = strlen(
namdMyNode->simParams->restartFilename);
718 char *restart_name =
new char[baselen+26];
719 const char *bsuffix =
".old";
721 strcpy(restart_name,
namdMyNode->simParams->restartFilename);
723 sprintf(timestepstr,
".%d",timestep);
724 strcat(restart_name, timestepstr);
727 strcat(restart_name,
".coor");
735 sprintf(comment,
"RESTART COORDINATES WRITTEN BY NAMD AT TIMESTEP %d", timestep);
737 #ifdef NODEGROUP_FORCE_REGISTER 739 CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
740 PatchData* pData = cpdata.ckLocalBranch();
741 pData->pdbData->set_all_positions(coor);
742 pData->pdbData->write(restart_name, comment);
748 namdMyNode->pdbData->write(restart_name, comment);
754 write_binary_file(restart_name, n, coor);
757 delete [] restart_name;
759 if (
namdMyNode->simParams->restartSaveDcd ) {
760 if ( ! output_dcdfile(
END_OF_RUN, 0, 0, 0, 0) ) {
761 const char *old_name =
namdMyNode->simParams->dcdFilename;
762 int old_len = strlen(old_name);
763 char *new_name =
new char[old_len+26];
764 strcpy(new_name, old_name);
765 if ( old_len >= 4 && ! strcmp(new_name+old_len-4,
".dcd") ) {
767 new_name[old_len] = 0;
769 sprintf(timestepstr,
".%d",timestep);
770 strcat(new_name, timestepstr);
771 strcat(new_name,
".dcd");
772 iout <<
"RENAMING COORDINATE DCD FILE " << old_name <<
" TO " << new_name <<
"\n" <<
endi;
774 while ( rename(old_name, new_name) ) {
775 if ( errno == EINTR || errno == EXDEV )
continue;
777 sprintf(err_msg,
"Unable to rename DCD file %s to %s", old_name, new_name);
801 void Output::output_restart_velocities(
int timestep,
int n,
Vector *vel)
805 char timestepstr[20];
807 int baselen = strlen(
namdMyNode->simParams->restartFilename);
808 char *restart_name =
new char[baselen+26];
809 const char *bsuffix =
".old";
811 strcpy(restart_name,
namdMyNode->simParams->restartFilename);
813 sprintf(timestepstr,
".%d",timestep);
814 strcat(restart_name, timestepstr);
817 strcat(restart_name,
".vel");
826 sprintf(comment,
"RESTART VELOCITIES WRITTEN BY NAMD AT TIMESTEP %d", timestep);
830 #ifdef NODEGROUP_FORCE_REGISTER 832 CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
833 PatchData* pData = cpdata.ckLocalBranch();
834 pData->pdbData->set_all_positions(vel);
835 pData->pdbData->write(restart_name, comment);
841 namdMyNode->pdbData->write(restart_name, comment);
848 write_binary_file(restart_name, n, vel);
851 delete [] restart_name;
861 if ( ! output )
return;
863 output->output_dcdfile(
END_OF_RUN, 0, 0, 0, 0);
865 for(
int dcdSelectionIndex=0; dcdSelectionIndex<16;++dcdSelectionIndex)
869 if(dcdSelectionFrequency)
870 output->output_dcdfile(
END_OF_RUN,0,0,0,dcdSelectionTag);
877 if ( ! output )
return;
884 replicaDcdActive = 1;
885 replicaDcdIndex = index;
889 replicaDcdActive = 1;
890 replicaDcdIndex = index;
893 msg->
srcPart = CmiMyPartition();
896 strcpy(msg->
data, filename);
901 replicaDcdActive = 1;
902 replicaDcdIndex = index;
905 msg->
srcPart = CmiMyPartition();
909 strcpy(msg->
data, filename);
917 iout <<
"CLOSING REPLICA DCD FILE " << msg->
dcdIndex <<
" " << f.filename.c_str() <<
"\n" <<
endi;
921 f.filename = (
const char*) msg->
data;
928 ( ! replicaDcdFiles.count(msg->
dcdIndex) )) {
930 sprintf(err_msg,
"Unknown replicaDcdFile identifier %d\n", msg->
dcdIndex);
937 iout <<
"OPENING REPLICA DCD FILE " << msg->
dcdIndex <<
" " << f.filename.c_str() <<
"\n" <<
endi;
943 sprintf(err_msg,
"DCD file %s already exists!!", f.filename.c_str());
945 }
else if (f.fileid < 0) {
948 sprintf(err_msg,
"Couldn't open DCD Index %d Select Index %d file %s", msg->
dcdIndex, msg->
dcdSelectIndex, f.filename.c_str());
950 sprintf(err_msg,
"Couldn't open DCD Index %d file %s", msg->
dcdIndex, f.filename.c_str());
952 }
else if (! f.fileid) {
953 NAMD_bug(
"Output::recvReplicaDcdData open_dcd_write returned fileid of zero");
962 NAMD_err(
"Writing of DCD header failed!!");
967 iout <<
"WRITING TO REPLICA DCD FILE " << msg->
dcdIndex <<
" " << f.filename.c_str() <<
"\n" <<
endi;
968 float *msgx = (
float*) msg->
data;
973 if (ret_code < 0)
NAMD_err(
"Writing of DCD step failed!!");
994 #define RAD2DEG 180.0/3.14159265359 996 int Output::output_dcdfile(
int timestep,
int n,
FloatVector *coor,
997 const Lattice *lattice,
int dcdSelectTag)
1000 static Bool first[
maxDCD]={
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true};
1001 static int fileid[
maxDCD];
1003 static float *x =
nullptr;
1004 static float *y =
nullptr;
1005 static float *z =
nullptr;
1006 static int n_alloc = 0;
1014 char *dcdFilename =
simParams->dcdFilename;
1015 int dcdSelectIndex=dcdSelectTag-1;
1016 if(dcdSelectTag >0 && dcdSelectTag <= 16)
1021 for ( std::map<int,replicaDcdFile>::iterator it = replicaDcdFiles.begin();
1022 it != replicaDcdFiles.end(); ++it ) {
1023 replicaDcdFile &f = it->second;
1025 iout <<
"CLOSING REPLICA DCD FILE " << it->first <<
" " << f.filename.c_str() <<
"\n" <<
endi;
1030 for ( std::map<std::pair<int,uint16_t>,replicaDcdFile>::iterator it = replicaDcdSelectFiles.begin();
1031 it != replicaDcdSelectFiles.end(); ++it ) {
1032 replicaDcdFile &f = it->second;
1034 iout <<
"CLOSING REPLICA DCD SELECT FILE " << it->first.first <<
" " << f.filename.c_str() <<
"\n" <<
endi;
1041 if ( ! first[dcdSelectTag] ) {
1042 iout <<
"CLOSING COORDINATE DCD FILE " << dcdFilename <<
"\n" <<
endi;
1045 iout <<
"COORDINATE DCD FILE " << dcdFilename <<
" WAS NOT CREATED\n" <<
endi;
1048 first[dcdSelectTag] = 1;
1049 fileid[dcdSelectTag] = 0;
1053 if ( replicaDcdActive ) {
1056 float *msgx = (
float*) msg->
data;
1057 float *msgy = msgx + n;
1058 float *msgz = msgy + n;
1059 for (i=0; i<n; i++) { msgx[i] = coor[i].
x; }
1060 for (i=0; i<n; i++) { msgy[i] = coor[i].
y; }
1061 for (i=0; i<n; i++) { msgz[i] = coor[i].
z; }
1069 msg->
NPRIV = timestep;
1073 msg->
srcPart = CmiMyPartition();
1079 if (first[dcdSelectTag])
1084 if ( n > n_alloc ) {
1093 iout <<
"OPENING COORDINATE DCD FILE\n" <<
endi;
1099 sprintf(err_msg,
"DCD file %s already exists!!",
1104 else if (fileid[dcdSelectTag] < 0)
1108 sprintf(err_msg,
"Couldn't open DCD file %s",
1114 int NSAVC, NFILE, NPRIV, NSTEP;
1120 NSTEP = NPRIV - NSAVC;
1126 n, NFILE, NPRIV, NSAVC, NSTEP,
1131 NAMD_err(
"Writing of DCD header failed!!");
1134 first[dcdSelectTag] =
FALSE;
1147 iout <<
"WRITING COORDINATES TO DCD SELECT FILE " << dcdFilename <<
" AT STEP " 1148 << timestep <<
"\n" <<
endi;
1150 iout <<
"WRITING COORDINATES TO DCD FILE " << dcdFilename <<
" AT STEP " 1151 << timestep <<
"\n" <<
endi;
1156 ret_code =
write_dcdstep(fileid[dcdSelectTag], n, x, y, z, unitcell);
1158 ret_code =
write_dcdstep(fileid[dcdSelectTag], n, x, y, z, NULL);
1162 NAMD_err(
"Writing of DCD step failed!!");
1184 void Output::output_final_coordinates(
Vector *coor,
int n,
int timestep)
1187 char output_name[140];
1191 strcpy(output_name,
namdMyNode->simParams->outputFilename);
1192 strcat(output_name,
".coor");
1200 sprintf(comment,
"FINAL COORDINATES WRITTEN BY NAMD AT TIMESTEP %d", timestep);
1202 #ifdef NODEGROUP_FORCE_REGISTER 1204 CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
1205 PatchData* pData = cpdata.ckLocalBranch();
1206 pData->pdbData->set_all_positions(coor);
1207 pData->pdbData->write(output_name, comment);
1212 namdMyNode->pdbData->set_all_positions(coor);
1213 namdMyNode->pdbData->write(output_name, comment);
1219 write_binary_file(output_name, n, coor);
1238 void Output::output_final_velocities(
int timestep,
int n,
Vector *vel)
1241 char output_name[140];
1245 strcpy(output_name,
namdMyNode->simParams->outputFilename);
1246 strcat(output_name,
".vel");
1254 sprintf(comment,
"FINAL VELOCITIES WRITTEN BY NAMD AT TIMESTEP %d", timestep);
1257 #ifdef NODEGROUP_FORCE_REGISTER 1259 CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
1260 PatchData* pData = cpdata.ckLocalBranch();
1261 pData->pdbData->set_all_positions(vel);
1262 pData->pdbData->write(output_name, comment);
1268 namdMyNode->pdbData->write(output_name, comment);
1275 write_binary_file(output_name, n, vel);
1296 void Output::output_veldcdfile(
int timestep,
int n,
FloatVector *vel)
1301 static float *x =
nullptr;
1302 static float *y =
nullptr;
1303 static float *z =
nullptr;
1304 static int n_alloc = 0;
1313 iout <<
"CLOSING VELOCITY DCD FILE\n" <<
endi;
1316 iout <<
"VELOCITY DCD FILE WAS NOT CREATED\n" <<
endi;
1328 if ( n > n_alloc ) {
1337 iout <<
"OPENING VELOCITY DCD FILE\n" <<
endi;
1345 sprintf(err_msg,
"Velocity DCD file %s already exists!!",
1350 else if (fileid < 0)
1354 sprintf(err_msg,
"Couldn't open velocity DCD file %s",
1360 int NSAVC, NFILE, NPRIV, NSTEP;
1363 NSTEP = NPRIV - NSAVC;
1367 const int with_unitcell = 0;
1370 n, NFILE, NPRIV, NSAVC, NSTEP,
1376 NAMD_err(
"Writing of velocity DCD header failed!!");
1391 iout <<
"WRITING VELOCITIES TO DCD FILE AT STEP " 1392 << timestep <<
"\n" <<
endi;
1398 NAMD_err(
"Writing of velocity DCD step failed!!");
1418 void Output::output_forces(
int timestep,
int n,
Vector *frc)
1421 char output_name[140];
1425 strcpy(output_name,
namdMyNode->simParams->outputFilename);
1426 strcat(output_name,
".force");
1434 sprintf(comment,
"FORCES WRITTEN BY NAMD AT TIMESTEP %d", timestep);
1435 #ifdef NODEGROUP_FORCE_REGISTER 1437 CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
1438 PatchData* pData = cpdata.ckLocalBranch();
1439 pData->pdbData->set_all_positions(frc);
1440 pData->pdbData->write(output_name, comment);
1446 namdMyNode->pdbData->write(output_name, comment);
1452 write_binary_file(output_name, n, frc);
1473 void Output::output_forcedcdfile(
int timestep,
int n,
FloatVector *frc)
1478 static float *x =
nullptr;
1479 static float *y =
nullptr;
1480 static float *z =
nullptr;
1481 static int n_alloc = 0;
1490 iout <<
"CLOSING FORCE DCD FILE\n" <<
endi;
1493 iout <<
"FORCE DCD FILE WAS NOT CREATED\n" <<
endi;
1503 if ( n > n_alloc ) {
1512 iout <<
"OPENING FORCE DCD FILE\n" <<
endi;
1520 sprintf(err_msg,
"Force DCD file %s already exists!!",
1525 else if (fileid < 0)
1529 sprintf(err_msg,
"Couldn't open force DCD file %s",
1535 int NSAVC, NFILE, NPRIV, NSTEP;
1538 NSTEP = NPRIV - NSAVC;
1542 const int with_unitcell = 0;
1545 n, NFILE, NPRIV, NSAVC, NSTEP,
1551 NAMD_err(
"Writing of force DCD header failed!!");
1566 iout <<
"WRITING FORCES TO DCD FILE AT STEP " 1567 << timestep <<
"\n" <<
endi;
1573 NAMD_err(
"Writing of force DCD step failed!!");
1593 void Output::write_binary_file(
char *fname,
int n,
Vector *vecs)
1602 sprintf(errmsg,
"Error on write to binary file %s", fname);
1627 void Output::scale_vels(
Vector *v,
int n,
Real fact)
1671 #ifdef MEM_OPT_VERSION 1672 void ParOutput::velocityMaster(
int timestep,
int n){
1676 if ( timestep >= 0 ) {
1680 ((timestep %
simParams->velDcdFrequency) == 0) )
1682 output_veldcdfile_master(timestep, n);
1687 ((timestep %
simParams->restartFrequency) == 0) )
1689 iout <<
"WRITING VELOCITIES TO RESTART FILE AT STEP " 1690 << timestep <<
"\n" <<
endi;
1691 output_restart_velocities_master(timestep, n);
1692 iout <<
"FINISHED WRITING RESTART VELOCITIES\n" <<
endi;
1703 iout <<
"WRITING VELOCITIES TO OUTPUT FILE AT STEP " 1704 << realstep <<
"\n" <<
endi;
1706 output_final_velocities_master(n);
1719 void ParOutput::velocitySlave(
int timestep,
int fID,
int tID,
Vector *vecs){
1722 if ( timestep >= 0 ) {
1726 ((timestep %
simParams->velDcdFrequency) == 0) )
1728 output_veldcdfile_slave(timestep, fID, tID, vecs);
1733 ((timestep %
simParams->restartFrequency) == 0) )
1736 output_restart_velocities_slave(timestep, fID, tID, vecs, offset);
1745 output_final_velocities_slave(fID, tID, vecs, offset);
1756 void ParOutput::output_veldcdfile_master(
int timestep,
int n){
1763 if ( ! veldcdFirst ) {
1764 iout <<
"CLOSING VELOCITY DCD FILE\n" <<
endi;
1767 iout <<
"VELOCITY DCD FILE WAS NOT CREATED\n" <<
endi;
1775 iout <<
"OPENING VELOCITY DCD FILE\n" <<
endi;
1777 #ifndef OUTPUT_SINGLE_FILE 1778 #error OUTPUT_SINGLE_FILE not defined! 1781 #if OUTPUT_SINGLE_FILE 1782 char *veldcdFilename =
simParams->velDcdFilename;
1784 char *veldcdFilename = buildFileName(
veldcdType);
1792 sprintf(err_msg,
"Velocity DCD file %s already exists!",veldcdFilename);
1795 else if (veldcdFileID < 0)
1798 sprintf(err_msg,
"Couldn't open velocity DCD file %s",veldcdFilename);
1802 #if !OUTPUT_SINGLE_FILE 1807 NAMD_write(veldcdFileID, (
char *) &tmpFlt,
sizeof(
float));
1812 int NSAVC, NFILE, NPRIV, NSTEP;
1815 NSTEP = NPRIV - NSAVC;
1819 const int with_unitcell = 0;
1822 n, NFILE, NPRIV, NSAVC, NSTEP,
1828 NAMD_err(
"Writing of velocity DCD header failed!!");
1831 #if !OUTPUT_SINGLE_FILE 1833 delete [] veldcdFilename;
1836 veldcdFirst =
FALSE;
1840 iout <<
"WRITING VELOCITIES TO DCD FILE AT STEP " 1841 << timestep <<
"\n" <<
endi;
1848 #if OUTPUT_SINGLE_FILE 1850 int totalAtoms =
namdMyNode->molecule->numAtoms;
1859 void ParOutput::output_veldcdfile_slave(
int timestep,
int fID,
int tID,
Vector *vecs){
1866 if ( ! veldcdFirst ) {
1869 #if OUTPUT_SINGLE_FILE 1877 int parN = tID-fID+1;
1882 #if OUTPUT_SINGLE_FILE 1883 char *veldcdFilename =
namdMyNode->simParams->velDcdFilename;
1885 char *veldcdFilename = buildFileName(
veldcdType);
1888 if(veldcdFileID < 0)
1891 sprintf(err_msg,
"Couldn't open velocity DCD file %s",veldcdFilename);
1894 #if OUTPUT_SINGLE_FILE 1899 veldcdX =
new float[parN];
1900 veldcdY =
new float[parN];
1901 veldcdZ =
new float[parN];
1908 #if !OUTPUT_SINGLE_FILE 1909 delete [] veldcdFilename;
1914 NAMD_write(veldcdFileID, (
char *) &tmpFlt,
sizeof(
float));
1915 NAMD_write(veldcdFileID, (
char *) &outputID,
sizeof(
int));
1916 NAMD_write(veldcdFileID, (
char *) &fID,
sizeof(
int));
1917 NAMD_write(veldcdFileID, (
char *) &tID,
sizeof(
int));
1920 veldcdFirst =
FALSE;
1923 #if OUTPUT_SINGLE_FILE 1927 CmiAssert(
sizeof(off_t)==8);
1928 int totalAtoms =
namdMyNode->molecule->numAtoms;
1930 for(
int i=0; i<parN; i++){
1931 veldcdX[i] = vecs[i].
x;
1932 veldcdY[i] = vecs[i].
y;
1933 veldcdZ[i] = vecs[i].
z;
1940 int atomsRemains = (totalAtoms-1)-(tID+1)+1;
1941 off_t offset = ((off_t)atomsRemains)*
sizeof(float)+1*
sizeof(
int);
1946 NAMD_write(veldcdFileID, (
char *)×tep,
sizeof(
int));
1952 void ParOutput::output_restart_velocities_master(
int timestep,
int n){
1953 #if OUTPUT_SINGLE_FILE 1954 char timestepstr[20];
1956 int baselen = strlen(
namdMyNode->simParams->restartFilename);
1957 char *restart_name =
new char[baselen+26];
1959 strcpy(restart_name,
namdMyNode->simParams->restartFilename);
1961 sprintf(timestepstr,
".%d",timestep);
1962 strcat(restart_name, timestepstr);
1964 strcat(restart_name,
".vel");
1966 char *restart_name = NULL;
1968 restart_name = buildFileName(
velType);
1970 restart_name = buildFileName(
velType,timestep);
1976 write_binary_file_master(restart_name, n);
1978 delete [] restart_name;
1981 void ParOutput::output_restart_velocities_slave(
int timestep,
int fID,
int tID,
Vector *vecs,
int64 offset){
1982 #if OUTPUT_SINGLE_FILE 1983 char timestepstr[20];
1985 int baselen = strlen(
namdMyNode->simParams->restartFilename);
1986 char *restart_name =
new char[baselen+26];
1988 strcpy(restart_name,
namdMyNode->simParams->restartFilename);
1990 sprintf(timestepstr,
".%d",timestep);
1991 strcat(restart_name, timestepstr);
1993 strcat(restart_name,
".vel");
1995 char *restart_name = NULL;
1997 restart_name = buildFileName(
velType);
1999 restart_name = buildFileName(
velType,timestep);
2005 write_binary_file_slave(restart_name, fID, tID, vecs, offset);
2007 delete [] restart_name;
2010 void ParOutput::output_final_velocities_master(
int n){
2011 #if OUTPUT_SINGLE_FILE 2012 char *output_name =
new char[strlen(
namdMyNode->simParams->outputFilename)+8];
2014 strcpy(output_name,
namdMyNode->simParams->outputFilename);
2015 strcat(output_name,
".vel");
2017 char *output_name = buildFileName(
velType);
2023 write_binary_file_master(output_name, n);
2026 void ParOutput::output_final_velocities_slave(
int fID,
int tID,
Vector *vecs,
int64 offset){
2027 #if OUTPUT_SINGLE_FILE 2028 char *output_name =
new char[strlen(
namdMyNode->simParams->outputFilename)+8];
2030 strcpy(output_name,
namdMyNode->simParams->outputFilename);
2031 strcat(output_name,
".vel");
2033 char *output_name = buildFileName(
velType);
2038 write_binary_file_slave(output_name, fID, tID, vecs, offset);
2040 delete [] output_name;
2043 void ParOutput::write_binary_file_master(
char *fname,
int n){
2047 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::write_binary_file_master\n");
2050 sprintf(errmsg,
"Error on write to binary file %s", fname);
2052 #if !OUTPUT_SINGLE_FILE 2057 NAMD_write(fd, (
char *) &tmpFlt,
sizeof(
float), errmsg);
2058 tmpInt =
namdMyNode->simParams->numoutputprocs;
2068 void ParOutput::write_binary_file_slave(
char *fname,
int fID,
int tID,
Vector *vecs,
int64 offset){
2070 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::write_binary_file_slave\n");
2071 #if OUTPUT_SINGLE_FILE 2073 FILE *ofp = fopen(fname,
"rb+");
2075 sprintf(errmsg,
"Error on opening binary file %s", fname);
2081 if ( _fseeki64(ofp, offset, SEEK_SET) )
2083 if ( fseeko(ofp, offset, SEEK_SET) )
2086 sprintf(errmsg,
"Error on seeking binary file %s", fname);
2091 FILE *ofp = fopen(fname,
"wb+");
2093 sprintf(errmsg,
"Error on opening binary file %s", fname);
2100 fwrite(&tmpInt,
sizeof(
int32), 1, ofp);
2101 fwrite(&tmpFlt,
sizeof(
float), 1, ofp);
2102 fwrite(&outputID,
sizeof(
int), 1, ofp);
2103 fwrite(&fID,
sizeof(
int), 1, ofp);
2104 fwrite(&tID,
sizeof(
int), 1, ofp);
2107 int parN = tID-fID+1;
2108 if ( fwrite(vecs,
sizeof(
Vector), parN, ofp) != parN ) {
2109 sprintf(errmsg,
"Error on writing to binary file %s", fname);
2113 if ( fclose(ofp) ) {
2114 sprintf(errmsg,
"Error on closing binary file %s", fname);
2122 void ParOutput::forceMaster(
int timestep,
int n){
2125 if ( timestep >= 0 ) {
2129 ((timestep %
simParams->forceDcdFrequency) == 0) )
2131 output_forcedcdfile_master(timestep, n);
2139 int realstep =
simParams->firstTimestep;
2140 iout <<
"WRITING FORCES TO OUTPUT FILE AT STEP " 2141 << realstep <<
"\n" <<
endi;
2143 output_forces_master(n);
2150 void ParOutput::forceSlave(
int timestep,
int fID,
int tID,
Vector *vecs){
2153 if ( timestep >= 0 ) {
2157 ((timestep %
simParams->forceDcdFrequency) == 0) )
2159 output_forcedcdfile_slave(timestep, fID, tID, vecs);
2168 output_forces_slave(fID, tID, vecs, offset);
2174 void ParOutput::output_forcedcdfile_master(
int timestep,
int n){
2181 if ( ! forcedcdFirst ) {
2182 iout <<
"CLOSING FORCE DCD FILE\n" <<
endi;
2185 iout <<
"FORCE DCD FILE WAS NOT CREATED\n" <<
endi;
2193 iout <<
"OPENING FORCE DCD FILE\n" <<
endi;
2195 #if OUTPUT_SINGLE_FILE 2196 char *forcedcdFilename =
simParams->forceDcdFilename;
2206 sprintf(err_msg,
"Force DCD file %s already exists!",forcedcdFilename);
2209 else if (forcedcdFileID < 0)
2212 sprintf(err_msg,
"Couldn't open force DCD file %s",forcedcdFilename);
2216 #if !OUTPUT_SINGLE_FILE 2221 NAMD_write(forcedcdFileID, (
char *) &tmpFlt,
sizeof(
float));
2226 int NSAVC, NFILE, NPRIV, NSTEP;
2229 NSTEP = NPRIV - NSAVC;
2233 const int with_unitcell = 0;
2236 n, NFILE, NPRIV, NSAVC, NSTEP,
2242 NAMD_err(
"Writing of force DCD header failed!!");
2245 #if !OUTPUT_SINGLE_FILE 2247 delete [] forcedcdFilename;
2250 forcedcdFirst =
FALSE;
2254 iout <<
"WRITING FORCES TO DCD FILE AT STEP " 2255 << timestep <<
"\n" <<
endi;
2262 #if OUTPUT_SINGLE_FILE 2264 int totalAtoms =
namdMyNode->molecule->numAtoms;
2273 void ParOutput::output_forcedcdfile_slave(
int timestep,
int fID,
int tID,
Vector *vecs){
2280 if ( ! forcedcdFirst ) {
2283 #if OUTPUT_SINGLE_FILE 2284 delete [] forcedcdX;
2285 delete [] forcedcdY;
2286 delete [] forcedcdZ;
2291 int parN = tID-fID+1;
2296 #if OUTPUT_SINGLE_FILE 2297 char *forcedcdFilename =
namdMyNode->simParams->forceDcdFilename;
2302 if(forcedcdFileID < 0)
2305 sprintf(err_msg,
"Couldn't open force DCD file %s",forcedcdFilename);
2308 #if OUTPUT_SINGLE_FILE 2313 forcedcdX =
new float[parN];
2314 forcedcdY =
new float[parN];
2315 forcedcdZ =
new float[parN];
2322 #if !OUTPUT_SINGLE_FILE 2323 delete [] forcedcdFilename;
2328 NAMD_write(forcedcdFileID, (
char *) &tmpFlt,
sizeof(
float));
2329 NAMD_write(forcedcdFileID, (
char *) &outputID,
sizeof(
int));
2330 NAMD_write(forcedcdFileID, (
char *) &fID,
sizeof(
int));
2331 NAMD_write(forcedcdFileID, (
char *) &tID,
sizeof(
int));
2334 forcedcdFirst =
FALSE;
2337 #if OUTPUT_SINGLE_FILE 2341 CmiAssert(
sizeof(off_t)==8);
2342 int totalAtoms =
namdMyNode->molecule->numAtoms;
2344 for(
int i=0; i<parN; i++){
2345 forcedcdX[i] = vecs[i].
x;
2346 forcedcdY[i] = vecs[i].
y;
2347 forcedcdZ[i] = vecs[i].
z;
2353 int atomsRemains = (totalAtoms-1)-(tID+1)+1;
2354 off_t offset = ((off_t)atomsRemains)*
sizeof(float)+1*
sizeof(
int);
2358 NAMD_write(forcedcdFileID, (
char *)×tep,
sizeof(
int));
2364 void ParOutput::output_forces_master(
int n){
2365 #if OUTPUT_SINGLE_FILE 2366 char *output_name =
new char[strlen(
namdMyNode->simParams->outputFilename)+8];
2368 strcpy(output_name,
namdMyNode->simParams->outputFilename);
2369 strcat(output_name,
".force");
2371 char *output_name = buildFileName(
forceType);
2377 write_binary_file_master(output_name, n);
2380 void ParOutput::output_forces_slave(
int fID,
int tID,
Vector *vecs,
int64 offset){
2381 #if OUTPUT_SINGLE_FILE 2382 char *output_name =
new char[strlen(
namdMyNode->simParams->outputFilename)+8];
2384 strcpy(output_name,
namdMyNode->simParams->outputFilename);
2385 strcat(output_name,
".force");
2387 char *output_name = buildFileName(
forceType);
2392 write_binary_file_slave(output_name, fID, tID, vecs, offset);
2394 delete [] output_name;
2400 void ParOutput::coordinateMaster(
int timestep,
int n,
Lattice &lat){
2403 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::coordinateMaster n "<< n <<
"\n");
2404 if ( timestep >= 0 ) {
2407 ((timestep %
simParams->dcdFrequency) == 0) )
2409 output_dcdfile_master(timestep, n,
2410 simParams->dcdUnitCell ? &lat : NULL, 0);
2415 for(
int index=0; index<16;++index)
2420 if(frequency>0 && (timestep % frequency) == 0)
2424 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::coordinateMaster index "<< index<<
" numpoints "<<dcdSelectionNpoints <<
"\n");
2425 output_dcdfile_master(timestep, dcdSelectionNpoints,
2426 simParams->dcdUnitCell ? &lat : NULL, tag);
2433 ((timestep %
simParams->restartFrequency) == 0) )
2435 iout <<
"WRITING COORDINATES TO RESTART FILE AT STEP " 2436 << timestep <<
"\n" <<
endi;
2437 output_restart_coordinates_master(timestep, n);
2438 iout <<
"FINISHED WRITING RESTART COORDINATES\n" <<
endi;
2469 iout <<
"WRITING COORDINATES TO OUTPUT FILE AT STEP " 2470 << realstep <<
"\n" <<
endi;
2472 output_final_coordinates_master(n);
2481 for(
int dcdSelectionIndex=0; dcdSelectionIndex<16;++dcdSelectionIndex)
2485 if(dcdSelectionFrequency)
2486 output_dcdfile_master(
END_OF_RUN,0,NULL, dcdSelectionTag);
2492 void ParOutput::coordinateSlave(
int timestep,
int fID,
int tID,
Vector *vecs,
FloatVector *fvecs){
2495 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::coordinateSlave fID "<<fID<<
" tID "<<tID<<
"\n");
2496 if ( timestep >= 0 ) {
2499 ((timestep %
simParams->dcdFrequency) == 0) )
2501 output_dcdfile_slave(timestep, fID, tID, fvecs, 0);
2505 bool needCleanup =
false;
2507 for(
int index=0; index<16;++index)
2511 if(frequency>0 && (timestep % frequency) == 0)
2513 int dcdSelectionNpoints = dcdSelectionLocalSize[index];
2515 if(dcdSelectionNpoints>0)
2519 off_t thisTID = dcdSelectionOffsets[index];
2520 DebugM(3,
"["<<CkMyPe()<<
"]"<<
"ParOutput::coordinateSlave index "<<index <<
" localSize "<<dcdSelectionNpoints<<
" offset "<< thisTID <<
"\n");
2521 for(
int i=0; i< dcdSelectionNpoints; ++i){
2523 dcdSelectionFcoor[i] = fvecs[dcdSelectionMap[index][i]-fID];
2524 DebugM(1,
"["<<CkMyPe()<<
"]"<<
"ParOutput::coordinateSlave index "<<index <<
" atom "<<i<<
" mapto "<< dcdSelectionMap[index][i]<<
" - fID "<< fID<<
" -> "<< dcdSelectionMap[index][i]-fID <<
" coords " << dcdSelectionFcoor[i] <<
"\n");
2526 output_dcdfile_slave(timestep, fID, thisTID+dcdSelectionNpoints-1, dcdSelectionFcoor, tag);
2527 delete [] dcdSelectionFcoor;
2535 ((timestep %
simParams->restartFrequency) == 0) )
2538 output_restart_coordinates_slave(timestep, fID, tID, vecs, offset);
2567 output_final_coordinates_slave(fID, tID, vecs, offset);
2576 for(
int index=0; index<16;++index)
2582 output_dcdfile_slave(
END_OF_RUN,0,0,NULL, tag);
2589 void ParOutput::output_dcdfile_master(
int timestep,
int n,
const Lattice *lattice,
int dcdSelectTag){
2593 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::output_dcdfile_master n "<< n <<
" tag "<< dcdSelectTag<<
"\n");
2597 if ( ! parFirst[dcdSelectTag] ) {
2598 iout <<
"CLOSING COORDINATE DCD FILE\n" <<
endi;
2601 iout <<
"COORDINATE DCD FILE WAS NOT CREATED\n" <<
endi;
2605 int dcdSelectIndex=dcdSelectTag-1;
2606 if (parFirst[dcdSelectTag])
2609 iout <<
"OPENING COORDINATE DCD FILE\n" <<
endi;
2611 #if OUTPUT_SINGLE_FILE 2612 char *dcdFilename =
simParams->dcdFilename;
2614 char *dcdFilename = buildFileName(
dcdType);
2616 if(dcdSelectTag >0 && dcdSelectTag <= 16)
2618 #ifndef OUTPUT_SINGLE_FILE 2620 NAMD_err(
"DCD selection not supported without OUTPUT_SINGLE_FILE!!");
2624 DebugM(3,
"DCD Selection File " << dcdFilename <<
" tag " << dcdSelectTag<<
"\n");
2631 sprintf(err_msg,
"DCD file %s already exists!!",dcdFilename);
2634 else if (parFileid[dcdSelectTag] < 0)
2637 sprintf(err_msg,
"Couldn't open DCD file %s",dcdFilename);
2641 #if !OUTPUT_SINGLE_FILE 2646 NAMD_write(parFileid[dcdSelectTag], (
char *) &tmpFlt,
sizeof(
float));
2651 int NSAVC, NFILE, NPRIV, NSTEP;
2652 NSAVC = (dcdSelectTag==0) ?
simParams->dcdFrequency :
2655 NSTEP = NPRIV - NSAVC;
2661 n, NFILE, NPRIV, NSAVC, NSTEP,
2667 NAMD_err(
"Writing of DCD header failed!!");
2670 #if !OUTPUT_SINGLE_FILE 2672 delete [] dcdFilename;
2675 parFirst[dcdSelectTag] =
FALSE;
2679 iout <<
"WRITING COORDINATES TO DCD FILE AT STEP " 2680 << timestep <<
"\n" <<
endi;
2695 #if OUTPUT_SINGLE_FILE 2697 int totalAtoms =
namdMyNode->molecule->numAtoms;
2698 if(dcdSelectTag >0 && dcdSelectTag <= 16)
2709 void ParOutput::output_dcdfile_slave(
int timestep,
int fID,
int tID,
FloatVector *fvecs,
int dcdSelectTag){
2712 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::output_dcdfile_slave fID "<<fID <<
" tID "<<tID <<
" tag "<< dcdSelectTag <<
"\n");
2716 if ( ! parFirst[dcdSelectTag] ) {
2719 #if OUTPUT_SINGLE_FILE 2731 int parN = tID-fID+1;
2732 int dcdSelectIndex=dcdSelectTag-1;
2733 if (parFirst[dcdSelectTag])
2735 #if OUTPUT_SINGLE_FILE 2736 char *dcdFilename =
simParams->dcdFilename;
2738 char *dcdFilename = buildFileName(
dcdType);
2740 if(dcdSelectTag >0 && dcdSelectTag <= 16)
2742 #ifndef OUTPUT_SINGLE_FILE 2744 NAMD_err(
"DCD selection not supported without OUTPUT_SINGLE_FILE!!");
2748 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" DCD Selection File " << dcdFilename <<
" tag " << dcdSelectTag<<
"\n");
2752 if(parFileid[dcdSelectTag] < 0)
2755 sprintf(err_msg,
"Couldn't open DCD file %s", dcdFilename);
2759 #if OUTPUT_SINGLE_FILE 2764 skipbytes +=
sizeof(int)*2 + 6*
sizeof(
double);
2766 seek_dcdfile(parFileid[dcdSelectTag], skipbytes, SEEK_SET);
2769 #if !OUTPUT_SINGLE_FILE 2770 delete [] dcdFilename;
2775 NAMD_write(parFileid[dcdSelectTag], (
char *) &tmpFlt,
sizeof(
float));
2776 NAMD_write(parFileid[dcdSelectTag], (
char *) &outputID,
sizeof(
int));
2777 NAMD_write(parFileid[dcdSelectTag], (
char *) &fID,
sizeof(
int));
2778 NAMD_write(parFileid[dcdSelectTag], (
char *) &tID,
sizeof(
int));
2780 parFirst[dcdSelectTag] =
FALSE;
2783 #if OUTPUT_SINGLE_FILE 2787 CmiAssert(
sizeof(off_t)==8);
2789 int totalAtoms =
namdMyNode->molecule->numAtoms;
2790 if(dcdSelectTag >0 && dcdSelectTag <= 16)
2796 if(parN > dcdAllocSize)
2804 dcdX =
new float[parN];
2805 dcdY =
new float[parN];
2806 dcdZ =
new float[parN];
2807 dcdAllocSize = parN;
2809 for(
int i=0; i<parN; i++){
2810 dcdX[i] = fvecs[i].
x;
2811 dcdY[i] = fvecs[i].
y;
2812 dcdZ[i] = fvecs[i].
z;
2827 int atomsRemains = (totalAtoms-1)-(tID+1)+1;
2828 off_t offset = ((off_t)atomsRemains)*
sizeof(float)+1*
sizeof(
int);
2831 offset +=
sizeof(int)*2 + 6*
sizeof(
double);
2833 seek_dcdfile(parFileid[dcdSelectTag], offset, SEEK_CUR);
2836 NAMD_write(parFileid[dcdSelectTag], (
char *)×tep,
sizeof(
int));
2842 void ParOutput::output_restart_coordinates_master(
int timestep,
int n){
2843 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::output_restart_coordinates_master\n");
2844 #if OUTPUT_SINGLE_FILE 2845 char timestepstr[20];
2847 int baselen = strlen(
namdMyNode->simParams->restartFilename);
2848 char *restart_name =
new char[baselen+26];
2850 strcpy(restart_name,
namdMyNode->simParams->restartFilename);
2852 sprintf(timestepstr,
".%d",timestep);
2853 strcat(restart_name, timestepstr);
2855 strcat(restart_name,
".coor");
2857 char *restart_name = NULL;
2859 restart_name = buildFileName(
coorType);
2861 restart_name = buildFileName(
coorType,timestep);
2867 write_binary_file_master(restart_name, n);
2869 delete [] restart_name;
2871 void ParOutput::output_restart_coordinates_slave(
int timestep,
int fID,
int tID,
Vector *vecs,
int64 offset){
2872 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::output_restart_coordinates_slave\n");
2873 #if OUTPUT_SINGLE_FILE 2874 char timestepstr[20];
2876 int baselen = strlen(
namdMyNode->simParams->restartFilename);
2877 char *restart_name =
new char[baselen+26];
2879 strcpy(restart_name,
namdMyNode->simParams->restartFilename);
2881 sprintf(timestepstr,
".%d",timestep);
2882 strcat(restart_name, timestepstr);
2884 strcat(restart_name,
".coor");
2886 char *restart_name = NULL;
2888 restart_name = buildFileName(
coorType);
2890 restart_name = buildFileName(
coorType,timestep);
2896 write_binary_file_slave(restart_name, fID, tID, vecs, offset);
2898 delete [] restart_name;
2901 void ParOutput::output_final_coordinates_master(
int n){
2902 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::output_final_coordinates_master\n");
2903 #if OUTPUT_SINGLE_FILE 2904 char *output_name =
new char[strlen(
namdMyNode->simParams->outputFilename)+8];
2907 strcpy(output_name,
namdMyNode->simParams->outputFilename);
2908 strcat(output_name,
".coor");
2910 char *output_name = buildFileName(
coorType);
2916 write_binary_file_master(output_name, n);
2918 delete [] output_name;
2920 void ParOutput::output_final_coordinates_slave(
int fID,
int tID,
Vector *vecs,
int64 offset){
2921 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::output_final_coordinates_slave\n");
2922 #if OUTPUT_SINGLE_FILE 2923 char *output_name =
new char[strlen(
namdMyNode->simParams->outputFilename)+8];
2926 strcpy(output_name,
namdMyNode->simParams->outputFilename);
2927 strcat(output_name,
".coor");
2929 char *output_name = buildFileName(
coorType);
2934 write_binary_file_slave(output_name, fID, tID, vecs, offset);
2936 delete [] output_name;
2941 #if !OUTPUT_SINGLE_FILE 2942 char *ParOutput::buildFileName(
OUTPUTFILETYPE type,
int timestep){
2943 char *filename = NULL;
2944 const char *typeName = NULL;
2950 typeName =
"forcedcd";
2953 typeName =
"veldcd";
2965 typeName =
"invalid";
2968 int baselen = strlen(
namdMyNode->simParams->outputFilename);
2969 filename =
new char[baselen+32];
2970 memset(filename, 0, baselen+32);
2973 strcpy(filename,
namdMyNode->simParams->outputFilename);
2976 if(access(filename, F_OK)!=0) {
2977 int ret =
MKDIR(filename);
2980 sprintf(errmsg,
"Error in creating top-level directory %s!", filename);
2986 strcat(filename, typeName);
2989 if(access(filename, F_OK)!=0) {
2990 int ret =
MKDIR(filename);
2993 sprintf(errmsg,
"Error in creating middle-level directory %s!", filename);
3002 if(outputID == -1) {
3004 if(timestep!=-9999) {
3006 sprintf(tmpstr,
"%smeta.%d",
PATHSEPSTR, timestep);
3012 sprintf(tmpstr,
"%s%d",
PATHSEPSTR, outputID);
3013 strcat(filename, tmpstr);
3015 if(access(filename, F_OK)!=0) {
3016 int ret =
MKDIR(filename);
3019 sprintf(errmsg,
"Error in creating last-level directory %s!", filename);
3024 if(timestep!=-9999) {
3026 sprintf(tmpstr,
"%s%s_%d.%d",
PATHSEPSTR,typeName,outputID,timestep);
3028 sprintf(tmpstr,
"%s%s_%d",
PATHSEPSTR,typeName,outputID);
3032 strcat(filename, tmpstr);
3037 void ParOutput::setDcdSelectionParams(
int index, off_t offset,
size_t size, std::vector<uint32> map )
3039 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::setDcdSelectionParams index "<< index <<
" offset " <<offset <<
" size " << size<<
"\n");
3040 dcdSelectionOffsets[index] = offset;
3041 dcdSelectionLocalSize[index] = size;
3042 dcdSelectionMap[index] = map;
DCDParams dcdSelectionParams[16]
int open_dcd_write_par_slave(char *dcdname)
void gather_velocities(int timestep, int N, FloatVector *velocities)
NAMD_HOST_DEVICE Vector c() const
void NAMD_err(const char *err_msg)
int get_atom_index_from_dcd_selection(const int index, const int atomIndex)
NAMD_HOST_DEVICE int c_p() const
void sendReplicaDcdInit(int dstPart, ReplicaDcdInitMsg *msg, int msgsize)
void setReplicaDcdIndex(int index)
int update_dcdstep_par_header(int fd)
void force(int timestep, int n, Vector *frc, FloatVector *ffrc)
Produce appropriate force for the current timestep.
SimParameters * simParameters
std::ostream & endi(std::ostream &s)
std::ostream & iWARN(std::ostream &s)
int get_clusterSize(int anum) const
void replicaDcdSelectInit(int index, const char *tag, const char *filename)
void gather_coordinates(int timestep, int N, FloatVector *coords)
#define OUTPUT_FILE_VERSION
Molecule stores the structural information for the system.
NAMD_HOST_DEVICE int b_p() const
int open_dcd_write(const char *dcdname)
void wrap_coor_int_dcd_selection(xVector *coor, Lattice &lattice, xDone *done, int index)
uint16_t find_or_create_dcd_selection_index(const char *keystr)
const int get_dcd_selection_size(const int index)
void wrap_coor(Vector *coor, Lattice &lattice, double *done)
void recvReplicaDcdInit(ReplicaDcdInitMsg *msg)
char outFilename[NAMD_FILENAME_BUFFER_SIZE]
int write_dcdstep_par_XYZUnits(int fd, int N)
static std::pair< int, int > coordinateNeeded(int timestep)
Check if the step requires to output the coordinates.
int write_dcdstep_par_cell(int fd, double *cell)
#define OUTPUT_MAGIC_NUMBER
void sendReplicaDcdData(int dstPart, ReplicaDcdDataMsg *msg, int msgsize)
NAMD_HOST_DEVICE BigReal length(void) const
void replicaDcdInit(int index, const char *filename)
void NAMD_bug(const char *err_msg)
void velocity(int timestep, int n, Vector *vel, FloatVector *fvel)
Produce appropriate velocity for the current timestep.
void coordinate(int timestep, int n, Vector *coor, FloatVector *fcoor, Lattice &lattice)
Produce appropriate coordinate output for the current timestep.
int get_dcd_selection_index_from_atom_id(const int index, const int atomIndex)
void recvReplicaDcdData(ReplicaDcdDataMsg *msg)
int write_dcdstep(int fd, int N, float *X, float *Y, float *Z, double *cell)
void wrap_coor_dcd_selection(Vector *coor, Lattice &lattice, double *done, int index)
NAMD_HOST_DEVICE int a_p() const
void NAMD_die(const char *err_msg)
static int forceNeeded(int timestep)
Check if the step requires to output the forces.
NAMD_HOST_DEVICE Vector b() const
int write_dcdheader(int fd, const char *filename, int N, int NFILE, int NPRIV, int NSAVC, int NSTEP, double DELTA, int with_unitcell)
void NAMD_backup_file(const char *filename, const char *extension)
void gather_box(int timestep, IMDBox *box)
void sendReplicaDcdAck(int dstPart, ReplicaDcdAckMsg *msg)
void gather_forces(int timestep, int N, FloatVector *forces)
static const short maxDCD
NAMD_HOST_DEVICE Vector wrap_nearest_delta(Position pos1) const
int write_dcdstep_par_slave(int fd, int parL, int parU, int N, float *X, float *Y, float *Z)
static int velocityNeeded(int timestep)
Check if the step requires to output the velocities.
int get_cluster(int anum) const
NAMD_HOST_DEVICE Vector a() const
void close_dcd_write(int fd)
NAMD_HOST_DEVICE Vector wrap_delta(const Position &pos1) const
void wrap_coor_int(xVector *coor, Lattice &lattice, xDone *done)
static void lattice_to_unitcell(const Lattice *lattice, double *unitcell)