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

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
 

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
}
 

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

◆ 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.

◆ 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

◆ 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 247 of file common.h.

247  {
248  dcdType,
249  forcedcdType,
250  veldcdType,
251  coorType,
252  forceType,
253  velType
254 };

◆ 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 435 of file common.C.

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

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

◆ Fopen()

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

Definition at line 341 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().

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

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

References Node::Object().

Referenced by Sequencer::algorithm(), Controller::algorithm(), CollectProxyVectorInstance::append(), CudaComputeNonbonded::assignPatches(), CudaComputeNonbonded::assignPatchesOnPe(), PmePencilXYZ::backwardDone(), LdbCoordinator::barrier(), 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(), 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::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(), 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(), 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(), 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(), Sync::Sync(), 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().

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

◆ NAMD_close()

void NAMD_close ( int  fd,
const char *  fname 
)

Definition at line 315 of file common.C.

References NAMD_err().

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

◆ NAMD_die()

void NAMD_die ( const char *  )

Definition at line 147 of file common.C.

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

◆ NAMD_err()

void NAMD_err ( const char *  )

Definition at line 170 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().

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

◆ NAMD_file_exists()

int NAMD_file_exists ( const char *  filename)

Definition at line 219 of file common.C.

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

Referenced by NAMD_backup_file().

219  {
220  int rval;
221  do {
222  rval = access(filename, F_OK);
223  } while ( rval != 0 && errno == EINTR );
224  if ( rval != 0 && errno != ENOENT ) {
225  const char *sys_err_msg = strerror(errno);
226  if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
227  iout << iERROR << "Error on checking file "
228  << filename << ": " << sys_err_msg << "\n" << endi;
229  fflush(stdout);
230  }
231  return ! rval;
232 }
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 102 of file common.C.

References NAMD_gcd().

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

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

◆ NAMD_open_text()

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

Definition at line 270 of file common.C.

References NAMD_err().

Referenced by ofstream_namd::open().

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

◆ NAMD_quit()

void NAMD_quit ( const char *  )

Definition at line 125 of file common.C.

References Node::Object().

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

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

◆ NAMD_stringdup()

char* NAMD_stringdup ( const char *  )

Definition at line 111 of file common.C.

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

◆ NAMD_version()

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

Definition at line 56 of file common.C.

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

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

◆ 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 51 of file common.C.

Referenced by NAMD_version().

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

◆ NAMD_write()

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

Definition at line 295 of file common.C.

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

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