NAMD
Classes | Macros | Typedefs | Enumerations | Functions
common.h File Reference
#include <unistd.h>
#include <stdio.h>
#include <climits>
#include <vector>
#include <cstdint>

Go to the source code of this file.

Classes

struct  dcd_params
 
struct  per_atom_flags
 

Macros

#define SEQUENCER_SOA
 
#define NAMD_FILENAME_BUFFER_SIZE   4096
 
#define COULOMB   332.0636
 
#define BOLTZMANN   0.001987191
 
#define TIMEFACTOR   48.88821
 
#define PRESSUREFACTOR   6.95E4
 
#define PDBVELFACTOR   20.45482706
 
#define PDBVELINVFACTOR   (1.0/PDBVELFACTOR)
 
#define PNPERKCALMOL   69.479
 
#define RECIP_TIMEFACTOR   (1.0 / TIMEFACTOR)
 
#define namdnearbyint(x)   floor((x)+0.5)
 
#define PI   3.141592653589793
 
#define TWOPI   2.0 * PI
 
#define ONE   1.000000000000000
 
#define ZERO   0.000000000000000
 
#define SMALLRAD   0.0005
 
#define SMALLRAD2   SMALLRAD*SMALLRAD
 
#define FALSE   0
 
#define TRUE   1
 
#define NO   0
 
#define YES   1
 
#define STRINGNULL   '\0'
 
#define MAX_NEIGHBORS   27
 
#define SIMPARAMSTAG   100
 
#define STATICPARAMSTAG   101
 
#define MOLECULETAG   102
 
#define FULLTAG   104
 
#define FULLFORCETAG   105
 
#define DPMTATAG   106
 
#define GRIDFORCEGRIDTAG   107
 
#define COMPUTEMAPTAG   108
 
#define CYCLE_BARRIER   0
 
#define PME_BARRIER   0
 
#define STEP_BARRIER   0
 
#define USE_BARRIER   (CYCLE_BARRIER || PME_BARRIER || STEP_BARRIER)
 
#define NAMD_SeparateWaters   0
 DMK - Atom Separation (water vs. non-water) More...
 
#define NAMD_ComputeNonbonded_SortAtoms   1
 
#define NAMD_ComputeNonbonded_SortAtoms_LessBranches   1
 
#define NAMD_HOST_DEVICE   inline
 
#define NAMD_UNIFIED_REDUCTION
 
#define CUDAGM_VERSION   2
 
#define CUDAGM_PASTER(x, y)   x ## y
 
#define CUDAGM_EVALUATOR(x, y)   CUDAGM_PASTER(x,y)
 
#define CUDAGM_NS   CUDAGM_EVALUATOR(v, CUDAGM_VERSION)
 

Typedefs

typedef int8_t int8
 
typedef int16_t int16
 
typedef int32_t int32
 
typedef int64_t int64
 
typedef uint8_t uint8
 
typedef uint16_t uint16
 
typedef uint32_t uint32
 
typedef uint64_t uint64
 
typedef float Real
 
typedef double BigReal
 
typedef int Bool
 
typedef struct dcd_params DCDParams
 
typedef struct per_atom_flags PerAtomFlags
 

Enumerations

enum  NAMD_ReleaseType { NAMD_UNKNOWN_RELEASE = 0, NAMD_ALPHA_RELEASE = 1, NAMD_BETA_RELEASE = 2, NAMD_FINAL_RELEASE = 3 }
 
enum  WaterModel { WaterModel::TIP3, WaterModel::TIP4, WaterModel::SWM4 }
 
enum  OUTPUTFILETYPE {
  dcdType, forcedcdType, veldcdType, coorType,
  forceType, velType
}
 
enum  IMDversion_t { IMDv2 =2, IMDv3 =3 }
 

Functions

void NAMD_version (int *major, int *minor, int *patchLevel, int *releaseType)
 
const char * NAMD_version_string (void)
 
void NAMD_quit (const char *)
 
void NAMD_die (const char *)
 
void NAMD_err (const char *)
 
void NAMD_bug (const char *)
 
int NAMD_file_exists (const char *filename)
 
void NAMD_backup_file (const char *filename, const char *extension=0)
 
int NAMD_open_text (const char *fname, int append=0)
 
void NAMD_write (int fd, const char *buf, size_t count, const char *fname="in NAMD_write()")
 
void NAMD_close (int fd, const char *fname)
 
char * NAMD_stringdup (const char *)
 
FILE * Fopen (const char *filename, const char *mode)
 
int Fclose (FILE *fout)
 
int NAMD_gcd (int a, int b)
 
constexpr int getWaterModelGroupSize (const WaterModel &watmodel)
 

Macro Definition Documentation

◆ BOLTZMANN

#define BOLTZMANN   0.001987191

◆ COMPUTEMAPTAG

#define COMPUTEMAPTAG   108

Definition at line 184 of file common.h.

Referenced by WorkDistrib::recvComputeMapChanges(), and WorkDistrib::sendComputeMap().

◆ COULOMB

#define COULOMB   332.0636

◆ CUDAGM_EVALUATOR

#define CUDAGM_EVALUATOR (   x,
 
)    CUDAGM_PASTER(x,y)

Definition at line 279 of file common.h.

◆ CUDAGM_NS

#define CUDAGM_NS   CUDAGM_EVALUATOR(v, CUDAGM_VERSION)

Definition at line 280 of file common.h.

◆ CUDAGM_PASTER

#define CUDAGM_PASTER (   x,
 
)    x ## y

Definition at line 278 of file common.h.

◆ CUDAGM_VERSION

#define CUDAGM_VERSION   2

Definition at line 277 of file common.h.

◆ CYCLE_BARRIER

#define CYCLE_BARRIER   0

Definition at line 186 of file common.h.

◆ DPMTATAG

#define DPMTATAG   106

Definition at line 182 of file common.h.

◆ FALSE

#define FALSE   0

◆ FULLFORCETAG

#define FULLFORCETAG   105

Definition at line 181 of file common.h.

Referenced by ComputeFullDirect::doWork().

◆ FULLTAG

#define FULLTAG   104

Definition at line 180 of file common.h.

Referenced by ComputeFullDirect::doWork().

◆ GRIDFORCEGRIDTAG

#define GRIDFORCEGRIDTAG   107

Definition at line 183 of file common.h.

Referenced by Node::reloadGridforceGrid().

◆ MAX_NEIGHBORS

#define MAX_NEIGHBORS   27

Definition at line 140 of file common.h.

◆ MOLECULETAG

#define MOLECULETAG   102

Definition at line 179 of file common.h.

Referenced by Node::resendMolecule().

◆ NAMD_ComputeNonbonded_SortAtoms

#define NAMD_ComputeNonbonded_SortAtoms   1

Definition at line 217 of file common.h.

◆ NAMD_ComputeNonbonded_SortAtoms_LessBranches

#define NAMD_ComputeNonbonded_SortAtoms_LessBranches   1

Definition at line 218 of file common.h.

◆ NAMD_FILENAME_BUFFER_SIZE

#define NAMD_FILENAME_BUFFER_SIZE   4096

◆ NAMD_HOST_DEVICE

#define NAMD_HOST_DEVICE   inline

Definition at line 237 of file common.h.

◆ NAMD_SeparateWaters

#define NAMD_SeparateWaters   0

DMK - Atom Separation (water vs. non-water)

Setting this define to a non-zero value will cause the HomePatches to separate the hydrogen groups in their HomePatch::atom lists (all water molecules first, in arbitrary order, followed by all non-waters, in arbitrary order).

Note from DH: This macro appears to be broken. After fixing basic compilation issues (undefined reference to simParams), enabling it causes an infinite loop when trying to run STMV.

Definition at line 204 of file common.h.

◆ NAMD_UNIFIED_REDUCTION

#define NAMD_UNIFIED_REDUCTION

Definition at line 273 of file common.h.

◆ namdnearbyint

#define namdnearbyint (   x)    floor((x)+0.5)

◆ NO

#define NO   0

Definition at line 132 of file common.h.

◆ ONE

#define ONE   1.000000000000000

Definition at line 100 of file common.h.

◆ PDBVELFACTOR

#define PDBVELFACTOR   20.45482706

◆ PDBVELINVFACTOR

#define PDBVELINVFACTOR   (1.0/PDBVELFACTOR)

Definition at line 58 of file common.h.

◆ PI

#define PI   3.141592653589793

◆ PME_BARRIER

#define PME_BARRIER   0

Definition at line 187 of file common.h.

◆ PNPERKCALMOL

#define PNPERKCALMOL   69.479

Definition at line 59 of file common.h.

◆ PRESSUREFACTOR

#define PRESSUREFACTOR   6.95E4

◆ RECIP_TIMEFACTOR

#define RECIP_TIMEFACTOR   (1.0 / TIMEFACTOR)

Definition at line 61 of file common.h.

Referenced by Sequencer::integrate_SOA().

◆ SEQUENCER_SOA

#define SEQUENCER_SOA

Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved.

Definition at line 15 of file common.h.

◆ SIMPARAMSTAG

#define SIMPARAMSTAG   100

Definition at line 177 of file common.h.

◆ SMALLRAD

#define SMALLRAD   0.0005

Definition at line 108 of file common.h.

◆ SMALLRAD2

#define SMALLRAD2   SMALLRAD*SMALLRAD

Definition at line 112 of file common.h.

◆ STATICPARAMSTAG

#define STATICPARAMSTAG   101

Definition at line 178 of file common.h.

Referenced by Node::resendMolecule().

◆ STEP_BARRIER

#define STEP_BARRIER   0

Definition at line 188 of file common.h.

◆ STRINGNULL

#define STRINGNULL   '\0'

◆ TIMEFACTOR

#define TIMEFACTOR   48.88821

◆ TRUE

#define TRUE   1

◆ TWOPI

#define TWOPI   2.0 * PI

◆ USE_BARRIER

#define USE_BARRIER   (CYCLE_BARRIER || PME_BARRIER || STEP_BARRIER)

Definition at line 190 of file common.h.

◆ YES

#define YES   1

Definition at line 133 of file common.h.

◆ ZERO

#define ZERO   0.000000000000000

Definition at line 104 of file common.h.

Referenced by ComputeNonbondedUtil::calcGBIS().

Typedef Documentation

◆ BigReal

typedef double BigReal

Definition at line 123 of file common.h.

◆ Bool

typedef int Bool

Definition at line 142 of file common.h.

◆ DCDParams

typedef struct dcd_params DCDParams

◆ int16

typedef int16_t int16

Definition at line 37 of file common.h.

◆ int32

typedef int32_t int32

Definition at line 38 of file common.h.

◆ int64

typedef int64_t int64

Definition at line 39 of file common.h.

◆ int8

typedef int8_t int8

Definition at line 36 of file common.h.

◆ PerAtomFlags

typedef struct per_atom_flags PerAtomFlags

◆ Real

typedef float Real

Definition at line 118 of file common.h.

◆ uint16

typedef uint16_t uint16

Definition at line 41 of file common.h.

◆ uint32

typedef uint32_t uint32

Definition at line 42 of file common.h.

◆ uint64

typedef uint64_t uint64

Definition at line 43 of file common.h.

◆ uint8

typedef uint8_t uint8

Definition at line 40 of file common.h.

Enumeration Type Documentation

◆ IMDversion_t

Enumerator
IMDv2 
IMDv3 

Definition at line 275 of file common.h.

275 {IMDv2=2, IMDv3=3};
Definition: common.h:275
Definition: common.h:275

◆ NAMD_ReleaseType

Enumerator
NAMD_UNKNOWN_RELEASE 
NAMD_ALPHA_RELEASE 
NAMD_BETA_RELEASE 
NAMD_FINAL_RELEASE 

Definition at line 147 of file common.h.

◆ OUTPUTFILETYPE

Enumerator
dcdType 
forcedcdType 
veldcdType 
coorType 
forceType 
velType 

Definition at line 240 of file common.h.

240  {
241  dcdType,
242  forcedcdType,
243  veldcdType,
244  coorType,
245  forceType,
246  velType
247 };

◆ WaterModel

enum WaterModel
strong
Enumerator
TIP3 
TIP4 
SWM4 

Definition at line 221 of file common.h.

221  {
222  TIP3,
223  TIP4,
224  SWM4, /* Drude model (5 charge sites) */
225 };

Function Documentation

◆ Fclose()

int Fclose ( FILE *  fout)

Definition at line 436 of file common.C.

Referenced by ConfigList::ConfigList(), Ambertoppar::genclose(), PDB::PDB(), read_binary_file(), and Parameters::read_parameter_file().

437 {
438  int rc = -1;
439 #if !defined(NOCOMPRESSED)
440  rc = pclose(fout);
441 #endif
442  if (rc == -1) // stream not associated with a popen()
443  {
444  rc = fclose(fout);
445  }
446  return rc;
447 } /* Fclose() */

◆ Fopen()

FILE* Fopen ( const char *  filename,
const char *  mode 
)

Definition at line 342 of file common.C.

References endi(), and iout.

Referenced by ConfigList::ConfigList(), Ambertoppar::genopen(), GridforceFullMainGrid::initialize(), PDB::PDB(), read_binary_file(), and Parameters::read_parameter_file().

343 {
344  struct stat buf;
345  // check if basic filename exists (and not a directory)
346 
347 #if defined(NOCOMPRESSED)
348  if (!stat(filename,&buf))
349  {
350  FILE *rval;
351  while ( ! (rval = fopen(filename,mode)) ) {
352  if ( errno != EINTR ) break;
353  }
354  return(rval);
355  }
356 #else
357  if (!stat(filename,&buf))
358  {
359  if (!S_ISDIR(buf.st_mode)) {
360  FILE *rval;
361  while ( ! (rval = fopen(filename,mode)) ) {
362  if ( errno != EINTR ) break;
363  }
364  return(rval);
365  }
366  }
367  // check for a compressed file
368  char *realfilename;
369  char *command;
370  FILE *fout;
371  command = (char *)malloc(strlen(filename)+25);
372  // check for .Z (unix compress)
373  sprintf(command,"zcat %s.Z",filename);
374  realfilename = command+5;
375  iout << "Command = " << command << "\n" << endi;
376  iout << "Filename.Z = " << realfilename << "\n" << endi;
377  if (!stat(realfilename,&buf))
378  {
379  if (!S_ISDIR(buf.st_mode))
380  {
381  fout = popen(command,mode);
382  // on HP-UX, the first character(s) out of pipe may be
383  // garbage! (Argh!)
384  int C;
385  do
386  {
387  C = fgetc(fout);
388  // iout << "C is " << C << "\n" << endi;
389  if (isalnum(C) || isspace(C))
390  {
391  ungetc(C,fout);
392  C = -1; // outta loop
393  }
394  } while(C != -1);
395  free(command);
396  return(fout);
397  }
398  }
399  // check for .gz (gzip)
400  sprintf(command,"gzip -d -c %s.gz",filename);
401  realfilename = command+11;
402  iout << "Command = " << command << "\n" << endi;
403  iout << "Filename.gz = " << realfilename << "\n" << endi;
404  if (!stat(realfilename,&buf))
405  {
406  if (!S_ISDIR(buf.st_mode))
407  {
408  fout = popen(command,mode);
409  // on HP-UX, the first character(s) out of pipe may be
410  // garbage! (Argh!)
411  int C;
412  do
413  {
414  C = fgetc(fout);
415  // iout << "C is " << C << "\n" << endi;
416  if (isalnum(C) || isspace(C))
417  {
418  ungetc(C,fout);
419  C = -1; // outta loop
420  }
421  } while(C != -1);
422  free(command);
423  return(fout);
424  }
425  }
426  free(command);
427 #endif /* !defined(NOCOMPRESSED) */
428 
429  return(NULL);
430 } /* Fopen() */
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51

◆ getWaterModelGroupSize()

constexpr int getWaterModelGroupSize ( const WaterModel watmodel)
inline

Definition at line 228 of file common.h.

References SWM4, TIP3, and TIP4.

Referenced by HomePatch::buildRattleList(), HomePatch::buildRattleList_SOA(), WorkDistrib::createAtomLists(), HomePatch::minimize_rattle2(), HomePatch::rattle1old(), and HomePatch::rattle2().

228  {
229  return (watmodel == WaterModel::TIP3) ? 3:
230  (watmodel == WaterModel::TIP4) ? 4:
231  (watmodel == WaterModel::SWM4) ? 5: -1;
232 }

◆ NAMD_backup_file()

void NAMD_backup_file ( const char *  filename,
const char *  extension = 0 
)

Definition at line 236 of file common.C.

References endi(), iERROR(), iout, and NAMD_file_exists().

Referenced by Controller::adaptTempInit(), colvarproxy_namd::backup_file(), ofstream_namd::open(), open_dcd_write(), Controller::outputExtendedSystem(), Controller::outputFepEnergy(), Controller::outputTiEnergy(), CollectionMaster::receiveDataStream(), and Controller::write_accelMDG_rest_file().

237 {
238  if (NAMD_file_exists(filename)) {
239  if ( ! extension ) extension = ".BAK";
240  char *backup = new char[strlen(filename)+strlen(extension)+1];
241  strcpy(backup, filename);
242  strcat(backup, extension);
243 #if defined(WIN32) && !defined(__CYGWIN__)
244  if ( remove(backup) ) if ( errno != ENOENT ) {
245  char *sys_err_msg = strerror(errno);
246  if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
247  iout << iERROR << "Error on removing file "
248  << backup << ": " << sys_err_msg << "\n" << endi;
249  fflush(stdout);
250  }
251 #endif
252  while ( rename(filename,backup) )
253  {
254  if ( errno == EINTR ) continue;
255  const char *sys_err_msg = strerror(errno);
256  if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
257  iout << iERROR << "Error on renaming file " << filename
258  << " to " << backup << ": " << sys_err_msg << "\n" << endi;
259  fflush(stdout);
260  if ( errno == EXDEV ) continue;
261  break;
262  // char errmsg[256];
263  // sprintf(errmsg, "Error on renaming file %s to %s",filename,backup);
264  // NAMD_err(errmsg);
265  }
266  delete [] backup;
267  }
268 }
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
int NAMD_file_exists(const char *filename)
Definition: common.C:220
#define iout
Definition: InfoStream.h:51
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:83

◆ NAMD_bug()

void NAMD_bug ( const char *  )

Definition at line 196 of file common.C.

References Node::Object().

Referenced by Sequencer::algorithm(), Controller::algorithm(), SynchronousCollectives::allGather(), SynchronousCollectives::allReduce(), SynchronousCollectives::alltoallv(), CollectProxyVectorInstance::append(), CudaComputeNonbonded::assignPatches(), CudaComputeNonbonded::assignPatchesOnPe(), PmePencilXYZ::backwardDone(), LdbCoordinator::barrier(), SynchronousCollectives::barrier(), SynchronousCollectives::broadcast(), HomePatch::buildRattleList_SOA(), HomePatch::buildSpanningTree(), ReductionMgr::buildSpanTree(), ComputeNonbondedUtil::calc_error(), Controller::calcPressure(), ComputePmeMgr::chargeGridReady(), checkSum(), ofstream_namd::close(), Box< Patch, CompAtom >::close(), Controller::compareChecksums(), ComputeCUDAMgr::ComputeCUDAMgr(), ComputePmeCUDAMgr::ComputePmeCUDAMgr(), ComputeTclBC::ComputeTclBC(), CudaPmeTranspose::copyDataDeviceToDevice(), CudaPmeTranspose::copyDataDeviceToHost(), CudaPmeTranspose::copyDataHostToDevice(), WorkDistrib::createAtomLists(), ComputeCUDAMgr::createCudaComputeNonbonded(), ComputePmeCUDAMgr::createDevicesAndAtomFiler(), CsmAckHandler(), CsmHandler(), cudaNAMD_bug(), CudaPmeOneDevice::CudaPmeOneDevice(), CudaPmeRealSpaceCompute::CudaPmeRealSpaceCompute(), MigrateAtomsCombinedMsg::distribute(), ComputeGridForce::doForce(), HomePatch::doGroupSizeCheck(), HomePatch::doGroupSizeCheck_SOA(), ComputePme::doWork(), CudaComputeNonbonded::doWork(), WorkDistrib::enqueueAngles(), WorkDistrib::enqueueAniso(), WorkDistrib::enqueueBonds(), WorkDistrib::enqueueCrossterms(), WorkDistrib::enqueueDihedrals(), WorkDistrib::enqueueExcls(), WorkDistrib::enqueueGromacsPair(), WorkDistrib::enqueueImpropers(), WorkDistrib::enqueueLCPO(), WorkDistrib::enqueueOneFourNbThole(), WorkDistrib::enqueuePme(), WorkDistrib::enqueueSelfA1(), WorkDistrib::enqueueSelfA2(), WorkDistrib::enqueueSelfA3(), WorkDistrib::enqueueSelfB1(), WorkDistrib::enqueueSelfB2(), WorkDistrib::enqueueSelfB3(), WorkDistrib::enqueueThole(), WorkDistrib::enqueueWork(), WorkDistrib::enqueueWorkA1(), WorkDistrib::enqueueWorkA2(), WorkDistrib::enqueueWorkA3(), WorkDistrib::enqueueWorkB1(), WorkDistrib::enqueueWorkB2(), WorkDistrib::enqueueWorkB3(), WorkDistrib::enqueueWorkC(), ScriptTcl::eval(), ComputeMap::extendPtrs(), findRecipEvirPe(), CudaComputeNonbonded::finishReductions(), ofstream_namd::flush(), SimpleBroadcastObject< Tensor >::get(), PmeAtomStorage::getAtomIndex(), getBlockDim(), CudaPmeTranspose::getBuffer(), ComputeCUDAMgr::getComputeCUDAMgr(), ComputeCUDAMgr::getCudaComputeNonbonded(), ComputePmeCUDAMgr::getDevice(), ComputePmeCUDAMgr::getDevicePencilY(), ComputePmeCUDAMgr::getDevicePencilZ(), ParseOptions::getfromptr(), ComputePmeCUDAMgr::getHomePencil(), ComputeLjPmeSerialMgr::getLJparameters(), Communicate::getMessage(), ComputePmeCUDAMgr::getNode(), getPencilDim(), Controller::getTotalPotentialEnergy(), globalAtomIDToSOAID(), GlobalGPUMgr::GlobalGPUMgr(), GridforceFullBaseGrid::grid_index(), FFTCompute::init(), ComputePmeCUDA::initialize(), ComputePatch::initialize(), ComputeHomePatch::initialize(), ComputePme::initialize(), LdbCoordinator::initialize(), ParallelIOMgr::initialize(), ComputePmeMgr::initialize(), ComputePmeMgr::initialize_computes(), IRSet::insert(), ParseOptions::issetfromptr(), ParseOptions::istruefromptr(), CudaComputeNonbonded::launchWork(), LdbCoordinator::LdbCoordinator(), ScriptTcl::load(), NamdState::loadStructure(), PatchMap::makePatches(), WorkDistrib::messageEnqueueWork(), CudaComputeNonbonded::messageEnqueueWork(), WorkDistrib::messageFinishCUDA(), WorkDistrib::messageFinishMIC(), HomePatch::minimize_rattle2(), Sequencer::multigratorPressure(), NAMD_version(), NAMD_write(), Node::Node(), PmeZPencil::node_process_untrans(), PmeYPencil::node_process_untrans(), ofstream_namd::open(), Box< Patch, CompAtom >::open(), CudaComputeNonbonded::openBoxesOnPe(), PatchMap::pack(), PatchMgr::PatchMgr(), CudaComputeNonbonded::patchReady(), PmePencilX::PmePencilX(), PmePencilXY::PmePencilXY(), PmePencilXYZ::PmePencilXYZ(), PmePencilY::PmePencilY(), PmePencilZ::PmePencilZ(), PmeTranspose::PmeTranspose(), ComputePmeMgr::pollChargeGridReady(), ComputePmeMgr::pollForcesReady(), PmePencilXYZMap::populateInitial(), PmePencilXMap::populateInitial(), PmePencilXYMap::populateInitial(), PmePencilMap::populateInitial(), Controller::printEnergies(), Rebalancer::printLoads(), PmePencilXMap::procNum(), PmePencilXYMap::procNum(), ProxyMgr::ProxyMgr(), HomePatch::rattle2(), Sequencer::reassignVelocities(), ProxyPatch::receiveAll(), ProxyPatch::receiveData(), ParallelIOMgr::receiveForces(), ParallelIOMgr::receivePositions(), ParallelIOMgr::receiveVelocities(), recursive_bisect_with_curve(), recvAck(), ComputePmeMgr::recvAck(), ComputePmeCUDADevice::recvAtoms(), ComputePmeCUDADevice::recvAtomsFromNeighbor(), recvBcast(), BroadcastMgr::recvBroadcast(), PatchMgr::recvCheckpointAck(), HomePatch::recvCheckpointLoad(), PatchMgr::recvCheckpointReq(), WorkDistrib::recvComputeMapChanges(), ComputeMgr::recvCudaGlobalMasterUpdateResultMsg(), GlobalMasterServer::recvData(), recvData(), ComputePmeCUDAMgr::recvDevices(), recvEvalCommand(), recvEvalResult(), PatchMgr::recvExchangeReq(), ComputePmeCUDADevice::recvForcesFromNeighbor(), ComputePmeMgr::recvGrid(), ComputeQMMgr::recvPartQM(), ComputePmeMgr::recvRecipEvir(), Output::recvReplicaDcdData(), ComputeGlobal::recvResults(), ProxyMgr::recvResults(), ComputePmeMgr::recvUngrid(), NodePmeMgr::recvUngrid(), ReductionSet::ReductionSet(), AtomMapper::registerIDsCompAtomExt(), AtomMapper::registerIDsFullAtom(), registerUserEventsForAllComputeObjs(), Node::reloadGridforceGrid(), ReductionMgr::remoteSubmit(), IRSet::remove(), replica_bcast(), replica_min_double(), RequireReductionShared::RequireReductionShared(), CollectProxyVectorInstance::reset(), CollectionMgr::CollectVectorInstance::reset(), CollectionMaster::CollectVectorInstance::reset(), ComputeGlobal::saveTotalForces(), Sequencer::scalePositionsVelocities(), ComputeNonbondedUtil::select(), PmeZPencil::send_ungrid(), PatchMgr::sendAtoms(), NodePmeMgr::sendDataHelper(), ComputePmeMgr::sendDataPart(), Communicate::sendMessage(), PatchMgr::sendMovePatches(), PatchMgr::sendOneHomePatch(), NodePmeMgr::sendPencilsHelper(), ComputePmeMgr::sendPencilsPart(), CudaPmeTranspose::setDataPtrsYZX(), CudaPmeTranspose::setDataPtrsZXY(), ComputePmeCUDADevice::setPencilProxy(), ComputePmeCUDAMgr::setupPencils(), SimpleBroadcastObject< Tensor >::SimpleBroadcastObject(), Box< Patch, CompAtom >::skip(), CudaComputeNonbonded::skipPatchesOnPe(), CudaPmeKSpaceCompute::solve(), Node::startup(), ComputeMap::storeCompute(), ComputePmeCUDA::storePmeForceMsg(), PmePencilXYZ::submitReductions(), PmePencilZ::submitReductions(), ComputePmeMgr::submitReductions(), SubmitReductionShared::SubmitReductionShared(), Sync::Sync(), SynchronousCollectives::SynchronousCollectives(), TopoManagerWrapper::TopoManagerWrapper(), CudaPmeTranspose::transposeXYZtoYZX(), CudaPmeTranspose::transposeXYZtoZXY(), IRSet::unchecked_insert(), ComputePme::ungridForces(), ComputeMap::unpack(), GridforceGrid::unpack_grid(), CudaComputeNonbonded::unregisterBoxesOnPe(), AtomMapper::unregisterIDsCompAtomExt(), AtomMapper::unregisterIDsFullAtom(), ComputeCUDAMgr::update(), ComputeMgr::updateComputes(), Node::updateGridScale(), WorkDistrib::WorkDistrib(), AtomMapper::~AtomMapper(), and Rebalancer::~Rebalancer().

197 {
198  if ( ! err_msg ) err_msg = "(unknown error)";
199  const char *bug_msg =
200  "FATAL ERROR: See http://www.ks.uiuc.edu/Research/namd/bugreport.html";
201  CkPrintf("FATAL ERROR: %s\n%s\n",err_msg, bug_msg);
202  fflush(stdout);
203  char repstr[24] = "";
204  if (CmiNumPartitions() > 1 ||
205  (Node::Object()->simParameters != 0 &&
206  Node::Object()->simParameters->CUDASOAintegrateMode)) {
207  sprintf(repstr,"REPLICA %d ", CmiMyPartition());
208  // CkAbort ensures that all replicas die
209  CkAbort("%sFATAL ERROR: %s\n%s\n", repstr, err_msg, bug_msg);
210  }
211  CkError("%sFATAL ERROR: %s\n%s\n", repstr, err_msg, bug_msg);
212 #if CHARM_VERSION < 61000
213  CkExit();
214 #else
215  CkExit(2);
216 #endif
217 }
static Node * Object()
Definition: Node.h:86

◆ NAMD_close()

void NAMD_close ( int  fd,
const char *  fname 
)

Definition at line 316 of file common.C.

References NAMD_err().

316  {
317 #if defined(WIN32) && !defined(__CYGWIN__)
318  while ( _close(fd) ) {
319 #else
320  while ( close(fd) ) {
321 #endif
322  if ( errno != EINTR ) {
323  char errmsg[1024];
324  sprintf(errmsg, "Error on closing file %s", fname);
325  NAMD_err(errmsg);
326  }
327  }
328 }
void NAMD_err(const char *err_msg)
Definition: common.C:171

◆ NAMD_die()

void NAMD_die ( const char *  )

Definition at line 148 of file common.C.

149 {
150  if ( ! err_msg ) err_msg = "(unknown error)";
151  CkPrintf("FATAL ERROR: %s\n", err_msg);
152  fflush(stdout);
153  char repstr[24] = "";
154  if (CmiNumPartitions() > 1 ||
155  (Node::Object()->simParameters != 0 &&
156  Node::Object()->simParameters->CUDASOAintegrateMode)) {
157  sprintf(repstr,"REPLICA %d ", CmiMyPartition());
158  // CkAbort ensures that all replicas die
159  CkAbort("%sFATAL ERROR: %s\n", repstr, err_msg);
160  }
161  CkError("%sFATAL ERROR: %s\n", repstr, err_msg);
162 #if CHARM_VERSION < 61000
163  CkExit();
164 #else
165  CkExit(1);
166 #endif
167 }
static Node * Object()
Definition: Node.h:86

◆ NAMD_err()

void NAMD_err ( const char *  )

Definition at line 171 of file common.C.

References Node::Object().

Referenced by after_backend_init(), ComputeQMMgr::calcMOPAC(), ComputeQMMgr::calcORCA(), ComputeQMMgr::calcUSR(), close_dcd_write(), colvarproxy_namd::error(), NAMD_close(), NAMD_open(), NAMD_open_text(), NAMD_seek(), NAMD_write(), Controller::outputExtendedSystem(), PDB::PDB(), AmberParm7Reader::read_amber_parm_stage1(), ComputeQMMgr::recvPartQM(), Output::recvReplicaDcdData(), and PDB::write().

172 {
173  if ( ! err_msg ) err_msg = "(unknown error)";
174  const char *sys_err_msg = strerror(errno);
175  if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
176  CkPrintf("FATAL ERROR: %s: %s\n", err_msg, sys_err_msg);
177  fflush(stdout);
178  char repstr[24] = "";
179  if (CmiNumPartitions() > 1 ||
180  (Node::Object()->simParameters != 0 &&
181  Node::Object()->simParameters->CUDASOAintegrateMode)) {
182  sprintf(repstr,"REPLICA %d ", CmiMyPartition());
183  // CkAbort ensures that all replicas die
184  CkAbort("%sFATAL ERROR: %s: %s\n", repstr, err_msg, sys_err_msg);
185  }
186  CkError("%sFATAL ERROR: %s: %s\n", repstr, err_msg, sys_err_msg);
187 #if CHARM_VERSION < 61000
188  CkExit();
189 #else
190  CkExit(1);
191 #endif
192 }
static Node * Object()
Definition: Node.h:86

◆ NAMD_file_exists()

int NAMD_file_exists ( const char *  filename)

Definition at line 220 of file common.C.

References endi(), iERROR(), and iout.

Referenced by NAMD_backup_file().

220  {
221  int rval;
222  do {
223  rval = access(filename, F_OK);
224  } while ( rval != 0 && errno == EINTR );
225  if ( rval != 0 && errno != ENOENT ) {
226  const char *sys_err_msg = strerror(errno);
227  if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
228  iout << iERROR << "Error on checking file "
229  << filename << ": " << sys_err_msg << "\n" << endi;
230  fflush(stdout);
231  }
232  return ! rval;
233 }
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:83

◆ NAMD_gcd()

int NAMD_gcd ( int  a,
int  b 
)

Definition at line 103 of file common.C.

References NAMD_gcd().

Referenced by Sequencer::integrate(), Sequencer::integrate_SOA(), and NAMD_gcd().

104 {
105  if(a == 0 || b == 0) return 0;
106  else if(a == b) return a;
107  else if(a > b) return NAMD_gcd(a-b,b);
108  return NAMD_gcd(a, b-a);
109 }
int NAMD_gcd(int a, int b)
Definition: common.C:103

◆ NAMD_open_text()

int NAMD_open_text ( const char *  fname,
int  append = 0 
)

Definition at line 271 of file common.C.

References NAMD_err().

Referenced by ofstream_namd::open().

271  {
272  int fd;
273 
274  // open the file and die if the open fails
275 #if defined(WIN32) && !defined(__CYGWIN__)
276  while ( (fd = _open(fname, O_WRONLY|(append?O_APPEND:O_EXCL)|O_CREAT|O_TEXT,_S_IREAD|_S_IWRITE)) < 0) {
277 #else
278 #ifdef NAMD_NO_O_EXCL
279  while ( (fd = open(fname, O_WRONLY|(append?O_APPEND:O_TRUNC)|O_CREAT,
280 #else
281  while ( (fd = open(fname, O_WRONLY|(append?O_APPEND:O_EXCL)|O_CREAT,
282 #endif
283  S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) {
284 #endif
285  if ( errno != EINTR ) {
286  char errmsg[1024];
287  sprintf(errmsg, "Unable to open text file %s", fname);
288  NAMD_err(errmsg);
289  }
290  }
291 
292  return fd;
293 }
void NAMD_err(const char *err_msg)
Definition: common.C:171

◆ NAMD_quit()

void NAMD_quit ( const char *  )

Definition at line 126 of file common.C.

References Node::Object().

Referenced by GlobalMasterIMD::get_vmd_forces(), and Controller::printTiming().

127 {
128  if ( ! err_msg ) err_msg = "(unknown error)";
129  CkPrintf("EXITING: %s\n", err_msg);
130  fflush(stdout);
131  char repstr[24] = "";
132  if (CmiNumPartitions() > 1
133  || Node::Object()->simParameters->CUDASOAintegrateMode) {
134  sprintf(repstr,"REPLICA %d ", CmiMyPartition());
135  // CkAbort ensures that all replicas die
136  CkAbort("%sEXITING: %s\n", repstr, err_msg);
137  }
138  CkError("%sEXITING: %s\n", repstr, err_msg);
139 #if CHARM_VERSION < 61000
140  CkExit();
141 #else
142  CkExit(0);
143 #endif
144 }
static Node * Object()
Definition: Node.h:86

◆ NAMD_stringdup()

char* NAMD_stringdup ( const char *  )

Definition at line 112 of file common.C.

112  {
113  char *rs;
114 
115  if(!s)
116  return NULL;
117 
118  rs = new char[strlen(s) + 1];
119  strcpy(rs,s);
120 
121  return rs;
122 }

◆ NAMD_version()

void NAMD_version ( int *  major,
int *  minor,
int *  patchLevel,
int *  releaseType 
)

Definition at line 57 of file common.C.

References NAMD_ALPHA_RELEASE, NAMD_BETA_RELEASE, NAMD_bug(), NAMD_FINAL_RELEASE, NAMD_UNKNOWN_RELEASE, and NAMD_version_string().

58 {
59  int NAMD_major = 0;
60  int NAMD_minor = 0;
61  int NAMD_patchLevel = 0;
62  int NAMD_releaseType = NAMD_UNKNOWN_RELEASE;
63 
64  // have to parse the version string to determine numbers
65  const char *vstr = NAMD_version_string();
66  char dot[4] = ""; // expect to read "."
67  char release[8] = ""; // expect to read "" or "."
68  // or "alpha" or "beta" or "final" or "release"
69  char extra[4] = ""; // bad version string if we read an extra character
70  int n = sscanf(vstr, "%d%3[^0-9]%d%7[^0-9]%d%c",
71  &NAMD_major, dot, &NAMD_minor, release, &NAMD_patchLevel, extra);
72  if (n < 3 || n > 5) {
73  NAMD_bug("Unable to parse NAMD_VERSION from Makefile");
74  }
75  if (n >= 4) {
76  if (strcmp(release, "a") == 0 || strcmp(release, "alpha") == 0) {
77  NAMD_releaseType = NAMD_ALPHA_RELEASE;
78  }
79  else if (strcmp(release, "b") == 0 || strcmp(release, "beta") == 0) {
80  NAMD_releaseType = NAMD_BETA_RELEASE;
81  }
82  else if (strcmp(release, ".") == 0 ||
83  strcmp(release, "final") == 0 ||
84  strcmp(release, "release") == 0 ||
85  strcmp(release, "patch") == 0) {
86  NAMD_releaseType = NAMD_FINAL_RELEASE;
87  }
88  else {
89  NAMD_bug("Unable to parse NAMD_VERSION from Makefile");
90  }
91  }
92  else {
93  NAMD_releaseType = NAMD_FINAL_RELEASE;
94  }
95  // now return values to caller
96  if (major != NULL) *major = NAMD_major;
97  if (minor != NULL) *minor = NAMD_minor;
98  if (patchLevel != NULL) *patchLevel = NAMD_patchLevel;
99  if (releaseType != NULL) *releaseType = NAMD_releaseType;
100 }
const char * NAMD_version_string()
Definition: common.C:52
void NAMD_bug(const char *err_msg)
Definition: common.C:196

◆ NAMD_version_string()

const char* NAMD_version_string ( void  )

Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved.

Definition at line 52 of file common.C.

Referenced by NAMD_version().

52  {
53  return NAMD_VERSION; // macro defined in toplevel Makefile
54 }

◆ NAMD_write()

void NAMD_write ( int  fd,
const char *  buf,
size_t  count,
const char *  fname = "in NAMD_write()" 
)

Definition at line 296 of file common.C.

References endi(), iout, iWARN(), NAMD_bug(), and NAMD_err().

296  {
297  while ( count ) {
298 #if defined(WIN32) && !defined(__CYGWIN__)
299  long retval = _write(fd,buf,count);
300 #else
301  ssize_t retval = write(fd,buf,count);
302 #endif
303  if ( retval < 0 && errno == EINTR ) retval = 0;
304  if ( retval < 0 ) {
305  char errmsg[1024];
306  sprintf(errmsg, "Error on writing to file %s", fname);
307  NAMD_err(errmsg);
308  }
309  if ( retval > count ) NAMD_bug("extra bytes written in NAMD_write()");
310  buf += retval;
311  count -= retval;
312  }
313 }
void NAMD_err(const char *err_msg)
Definition: common.C:171
void NAMD_bug(const char *err_msg)
Definition: common.C:196