BackEnd.C File Reference

#include "BackEnd.h"
#include "ProcessorPrivate.h"
#include "common.h"
#include "Node.h"
#include "memusage.h"
#include <new>
#include "Lattice.h"
#include "ComputeMoa.h"
#include "ComputeMsmMsa.h"
#include "main.decl.h"
#include "main.h"
#include "BOCgroup.h"
#include "WorkDistrib.decl.h"
#include "ProxyMgr.decl.h"
#include "PatchMgr.decl.h"
#include "DataExchanger.decl.h"
#include "ReductionMgr.decl.h"
#include "CollectionMgr.decl.h"
#include "CollectionMaster.decl.h"
#include "CollectionMgr.h"
#include "CollectionMaster.h"
#include "BroadcastMgr.decl.h"
#include "LdbCoordinator.decl.h"
#include "Sync.decl.h"
#include <tcl.h>

Go to the source code of this file.

Functions

void _initCharm (int, char **)
 CkpvStaticDeclare (int, exitSchedHndlr)
void exit_sched (void *msg)
static void register_exit_sched (void)
void NAMD_new_handler ()
void topo_getargs (char **)
void cuda_getargs (char **)
void cuda_affinity_initialize ()
void mic_getargs (char **)
void all_init (int argc, char **argv)
void after_backend_init (int argc, char **argv)
void master_init (int argc, char **argv)
void slave_init (int argc, char **argv)
void cuda_finalize ()

Variables

float cpuTime_start
float wallTime_start
char * gNAMDBinaryName = NULL

Function Documentation

void _initCharm ( int  ,
char **   
)

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

Referenced by all_init().

void after_backend_init ( int  argc,
char **  argv 
)

Definition at line 54 of file mainfunc.C.

References CHDIR, CWDSIZE, endi(), ScriptTcl::eval(), BackEnd::exit(), GETCWD, iINFO(), iout, j, ScriptTcl::load(), NAMD_die(), NAMD_err(), Node::Object(), PATHSEP, PATHSEPSTR, ScriptTcl::run(), Node::setScript(), and ScriptTcl::tclmain().

Referenced by main(), and slave_init().

00054                                               {
00055 #define CWDSIZE 1024
00056   char origcwd_buf[CWDSIZE];
00057   char currentdir_buf[CWDSIZE];
00058 
00059   ScriptTcl *script = new ScriptTcl;
00060   Node::Object()->setScript(script);
00061 
00062   for(argc = 0; argv[argc]; ++argc);
00063   if ( argc < 2 ) {
00064 #if defined(WIN32) && !defined(__CYGWIN__)
00065     CkPrintf("\nFATAL ERROR: No simulation config file specified on command line.\n");
00066     CkPrintf("\nNOTE: NAMD has no graphical interface and must be run from a command line.\n");
00067     int nsleep = 10;
00068     CkPrintf("\nSleeping %d seconds before exiting...\n", nsleep);
00069     fflush(stdout);
00070     sleep(nsleep);
00071     CkPrintf("\n");
00072 #endif
00073     NAMD_die("No simulation config file specified on command line.");
00074   }
00075   char *origcwd = GETCWD(origcwd_buf,CWDSIZE);
00076   if ( ! origcwd ) NAMD_err("getcwd");
00077 #ifdef NAMD_TCL
00078   for(int i = 1; i < argc; ++i) {
00079   if ( strstr(argv[i],"--") == argv[i] ) {
00080     char buf[1024];
00081     if ( i + 1 == argc ) {
00082       sprintf(buf, "missing argument for command line option %s", argv[i]);
00083       NAMD_die(buf);
00084     }
00085     if ( ! strcmp(argv[i],"--tclmain") ) {
00086       // pass all remaining arguments to script
00087       iout << iINFO << "Command-line argument is";
00088       for ( int j=i; j<argc; ++j ) { iout << " " << argv[j]; }
00089       iout << "\n" << endi;
00090       script->tclmain(argc-i-1,argv+i+1);
00091       BackEnd::exit();
00092       return;
00093     }
00094     sprintf(buf, "%s %s", argv[i]+2, argv[i+1]);
00095     iout << iINFO << "Command-line argument is --" << buf << "\n" << endi;
00096     script->eval(buf);
00097     ++i;
00098     continue;
00099   }
00100   char *confFile = argv[i];
00101 #else
00102   char *confFile = argv[argc-1];
00103 #endif
00104   iout << iINFO << "Configuration file is " << confFile << "\n" << endi;
00105 
00106   char *currentdir=confFile;
00107   char *tmp;
00108   char tmpcurdir[3];
00109   for(tmp=confFile;*tmp;++tmp); // find final null
00110   for( ; tmp != confFile && *tmp != PATHSEP; --tmp); // find last '/'
00111 #if defined(WIN32) && !defined(__CYGWIN__)
00112   if (tmp == confFile) {
00113     // in case this is under cygwin, search for '/' as well
00114     for(tmp=confFile;*tmp;++tmp); // find final null
00115     for( ; tmp != confFile && *tmp != '/'; --tmp); // find last '/'
00116   }
00117 #endif
00118   if ( CHDIR(origcwd) ) NAMD_err(origcwd);
00119   if ( tmp != confFile )
00120   {
00121     *tmp = 0; confFile = tmp + 1;
00122     if ( CHDIR(currentdir) ) NAMD_err(currentdir);
00123     struct stat statBuf;
00124     if (stat(confFile, &statBuf)) {
00125       char buf[1024];
00126       sprintf(buf,"Unable to access config file %s%c%s",currentdir,PATHSEP,confFile);
00127       NAMD_die(buf);
00128     }
00129     iout << iINFO << "Changed directory to " << currentdir << "\n" << endi;
00130     currentdir = GETCWD(currentdir_buf,CWDSIZE);
00131     if ( ! currentdir ) NAMD_err("getcwd after chdir");
00132   }
00133   else{
00134       if ( *tmp == PATHSEP ){ // config file in / is odd, but it might happen
00135           if ( CHDIR(PATHSEPSTR) ) NAMD_err(PATHSEPSTR);
00136           struct stat statBuf;
00137           if (stat(confFile, &statBuf)) {
00138             char buf[1024];
00139             sprintf(buf,"Unable to access config file %s",confFile);
00140             NAMD_die(buf);
00141           }
00142       }else{ // just a config file name, so the path is the current working path
00143           struct stat statBuf;
00144           if (stat(confFile, &statBuf)) {
00145             char buf[1024];
00146             if ( confFile[0] == '-' || confFile[0] == '+' ) {
00147               sprintf(buf,"Unknown command-line option %s",confFile);
00148             } else {
00149               sprintf(buf,"Unable to access config file %s",confFile);
00150             }
00151             NAMD_die(buf);
00152           }
00153           tmpcurdir[0] = '.';
00154           tmpcurdir[1] = PATHSEP;
00155           tmpcurdir[2] = 0;
00156           currentdir = tmpcurdir;
00157           iout << iINFO << "Working in the current directory " << origcwd << "\n" << endi;
00158       }
00159   }
00160 
00161 #ifdef MEM_OPT_VERSION
00162     int dirlen = strlen(currentdir);
00163     gWorkDir = new char[dirlen+1];
00164     gWorkDir[dirlen]=0;
00165     memcpy(gWorkDir, currentdir, dirlen);
00166 #endif
00167 
00168   currentdir = NULL;
00169 
00170 #ifdef NAMD_TCL
00171   script->load(confFile);
00172 #else
00173   script->run(confFile);
00174 #endif
00175 
00176 #ifdef NAMD_TCL
00177 }
00178   script->run();
00179 #endif
00180 
00181   BackEnd::exit();
00182 }

void all_init ( int  argc,
char **  argv 
)

Definition at line 99 of file BackEnd.C.

References _initCharm(), cuda_affinity_initialize(), cuda_getargs(), mic_getargs(), NAMD_new_handler(), ProcessorPrivateInit(), register_exit_sched(), and topo_getargs().

Referenced by master_init(), and slave_init().

00100 {
00101 #if defined(WIN32) && !defined(__CYGWIN__) && !defined(__MINGW_H)
00102   _set_new_handler(NAMD_new_handler);
00103 #else
00104   std::set_new_handler(NAMD_new_handler);
00105 #endif
00106   ProcessorPrivateInit();
00107   register_exit_sched();
00108   CmiGetArgFlag(argv, "+idlepoll");  // remove +idlepoll if it's still there
00109   topo_getargs(argv);
00110 #ifdef NAMD_CUDA
00111   cuda_getargs(argv);
00112   argc = CmiGetArgc(argv);
00113 #endif
00114 #ifdef NAMD_MIC
00115   CmiGetArgFlag(argv, "+idlepoll");  // remove +idlepoll if it's still there
00116   mic_getargs(argv);
00117   argc = CmiGetArgc(argv);
00118 #endif
00119 #ifdef NAMD_AVXTILES
00120   avxTilesCommandLineDisable = CmiGetArgFlag(argv, "+notiles");
00121 #endif
00122   
00123 #ifdef NAMD_CUDA
00124   // launch CUDA runtime threads before affinity is set by _initCharm
00125   // _initCharm contains a node barrier so there is no race here
00126   if(CmiMyRank()==0){
00127     cuda_affinity_initialize();
00128   }
00129 #endif
00130 
00131   _initCharm(argc, argv);  // message main Chare
00132 
00133 //#if 0  // moved to WorkDistrib
00134 //#ifdef NAMD_CUDA
00135 //  if ( CkMyPe() < CkNumPes() ) cuda_initialize();
00136 //#endif
00137 //#ifdef NAMD_MIC
00138 //  if ( CkMyPe() < CkNumPes() ) mic_initialize();
00139 //#endif
00140 //#endif
00141 }

CkpvStaticDeclare ( int  ,
exitSchedHndlr   
)
void cuda_affinity_initialize (  ) 

Definition at line 33 of file CudaUtils.C.

Referenced by all_init().

00033                                 {
00034   int devcnt = 0;
00035   cudaError_t err = cudaGetDeviceCount(&devcnt);
00036   if ( devcnt == 1 ) {  // only one device so it must be ours
00037     int *dummy;
00038     if ( err == cudaSuccess ) err = cudaSetDevice(0);
00039     if ( err == cudaSuccess ) err = cudaSetDeviceFlags(cudaDeviceMapHost);
00040     if ( err == cudaSuccess ) err = cudaMalloc(&dummy, 4);
00041   }
00042   if ( err != cudaSuccess ) {
00043     char host[128];
00044     gethostname(host, 128);  host[127] = 0;
00045     fprintf(stderr,"CUDA initialization error on %s: %s\n", host, cudaGetErrorString(err));
00046   }
00047 }

void cuda_finalize (  ) 

Definition at line 26 of file DeviceCUDA.C.

Referenced by BackEnd::exit().

00026                      {
00027     int ndevs = 0;
00028     cudaGetDeviceCount(&ndevs);
00029     for ( int dev=0; dev < ndevs; ++dev ) {
00030         cudaSetDevice(dev);
00031         cudaDeviceReset();
00032     }
00033 }

void cuda_getargs ( char **   ) 

Definition at line 51 of file DeviceCUDA.C.

References cuda_args, cuda_args_t::devicelist, cuda_args_t::devicesperreplica, cuda_args_t::ignoresharing, cuda_args_t::mergegrids, NAMD_die(), cuda_args_t::nomergegrids, cuda_args_t::nostreaming, and cuda_args_t::usedevicelist.

Referenced by all_init().

00051                                {
00052   cuda_args.devicelist = 0;
00053   cuda_args.usedevicelist = CmiGetArgStringDesc(argv, "+devices", &cuda_args.devicelist,
00054                 "comma-delimited list of CUDA device numbers such as 0,2,1,2");
00055   cuda_args.devicesperreplica = 0;
00056   CmiGetArgInt(argv, "+devicesperreplica", &cuda_args.devicesperreplica);
00057   if ( cuda_args.devicesperreplica < 0 ) NAMD_die("Devices per replica must be positive\n");
00058   cuda_args.ignoresharing = CmiGetArgFlag(argv, "+ignoresharing");
00059   cuda_args.mergegrids = CmiGetArgFlag(argv, "+mergegrids");
00060   cuda_args.nomergegrids = CmiGetArgFlag(argv, "+nomergegrids");
00061   if ( cuda_args.mergegrids && cuda_args.nomergegrids ) NAMD_die("Do not specify both +mergegrids and +nomergegrids");
00062   cuda_args.nostreaming = CmiGetArgFlag(argv, "+nostreaming");
00063 }

void exit_sched ( void *  msg  ) 

Definition at line 55 of file BackEnd.C.

Referenced by register_exit_sched().

00056 {
00057   //  CmiPrintf("Exiting scheduler on %d\n",CmiMyPe());
00058   CsdExitScheduler();
00059 }

void master_init ( int  argc,
char **  argv 
)

Definition at line 167 of file BackEnd.C.

References all_init(), BOCgroup::broadcastMgr, BOCgroup::collectionMgr, BOCgroup::computeCUDAMgr, BOCgroup::computeExtMgr, BOCgroup::computeFmmSerialMgr, BOCgroup::computeGBISserMgr, BOCgroup::computeMgr, BOCgroup::computeMsmMgr, BOCgroup::computeMsmMsaMgr, BOCgroup::computeMsmSerialMgr, BOCgroup::computePmeCUDAMgr, BOCgroup::computeQMMgr, cpuTime_start, BOCgroup::dataExchanger, GroupInitMsg::group, BOCgroup::ioMgr, BOCgroup::ldbCoordinator, SlaveInitMsg::master, BOCgroup::multicastMgr, BOCgroup::nodePmeMgr, BOCgroup::patchMgr, BOCgroup::proxyMgr, BOCgroup::reductionMgr, BOCgroup::sync, wallTime_start, and BOCgroup::workDistrib.

Referenced by BackEnd::init(), and slave_init().

00167                                        {
00168   cpuTime_start = CmiCpuTimer();
00169   wallTime_start = CmiWallTimer();
00170   if ( CmiMyPe() ) {
00171     all_init(argc, argv);
00172     CsdScheduler(-1);
00173     ConverseExit();  // should never return
00174   }
00175 
00176   all_init(argc, argv);
00177 
00178   // Create branch-office chares
00179   BOCgroup group;
00180   group.workDistrib = CProxy_WorkDistrib::ckNew();
00181   group.proxyMgr = CProxy_ProxyMgr::ckNew();
00182   group.patchMgr = CProxy_PatchMgr::ckNew();
00183   group.computeMgr = CProxy_ComputeMgr::ckNew();
00184   group.reductionMgr = CProxy_ReductionMgr::ckNew();
00185   // group.computePmeMgr set in constructor during startup
00186   group.nodePmeMgr = CProxy_NodePmeMgr::ckNew();
00187 #ifdef NAMD_CUDA
00188   group.computePmeCUDAMgr = CProxy_ComputePmeCUDAMgr::ckNew();
00189   group.computeCUDAMgr = CProxy_ComputeCUDAMgr::ckNew();
00190 #endif
00191 #ifdef OPENATOM_VERSION
00192   group.computeMoaMgr = CProxy_ComputeMoaMgr::ckNew();
00193 #endif // OPENATOM_VERSION
00194   group.computeExtMgr = CProxy_ComputeExtMgr::ckNew();
00195   group.computeQMMgr = CProxy_ComputeQMMgr::ckNew();
00196   group.computeGBISserMgr = CProxy_ComputeGBISserMgr::ckNew();
00197   group.computeFmmSerialMgr = CProxy_ComputeFmmSerialMgr::ckNew();
00198   group.computeMsmSerialMgr = CProxy_ComputeMsmSerialMgr::ckNew();
00199 #ifdef CHARM_HAS_MSA
00200   group.computeMsmMsaMgr = CProxy_ComputeMsmMsaMgr::ckNew();
00201 #endif
00202   group.computeMsmMgr = CProxy_ComputeMsmMgr::ckNew();
00203   // Charm CkMulticast library module
00204   group.multicastMgr = CProxy_CkMulticastMgr::ckNew();
00205 #ifdef MEM_OPT_VERSION
00206   group.ioMgr=CProxy_ParallelIOMgr::ckNew();
00207 #endif
00208 
00209   group.sync = CProxy_Sync::ckNew();
00210 
00211   #ifdef USE_NODEPATCHMGR
00212   group.nodeProxyMgr = CProxy_NodeProxyMgr::ckNew();
00213   #endif
00214   
00215 #if     CMK_SMP && USE_CKLOOP
00216   group.ckLoop = CkLoop_Init();
00217 #endif
00218 
00219   CkChareID collectionMaster = CProxy_CollectionMaster::ckNew(0);  
00220   SlaveInitMsg *initmsg7 = new SlaveInitMsg;
00221   initmsg7->master = collectionMaster;
00222   group.collectionMgr = CProxy_CollectionMgr::ckNew(initmsg7);
00223 
00224   group.broadcastMgr = CProxy_BroadcastMgr::ckNew();
00225   group.ldbCoordinator = CProxy_LdbCoordinator::ckNew();
00226 
00227   group.dataExchanger = CProxy_DataExchanger::ckNew();
00228 
00229   GroupInitMsg *msg = new GroupInitMsg;
00230   msg->group = group;
00231   CkGroupID node = CProxy_Node::ckNew(msg);
00232  
00233   CkStartQD(CkCallback(CkIndex_Node::exitScheduler(), CkMyPe(), node));
00234   CsdScheduler(-1);
00235 }

void mic_getargs ( char **   ) 

Referenced by all_init().

void NAMD_new_handler (  ) 

Definition at line 77 of file BackEnd.C.

References NAMD_die().

Referenced by all_init().

00077                         {
00078 #endif
00079   char tmp[100];
00080   sprintf(tmp,"Memory allocation failed on processor %d.",CmiMyPe());
00081   NAMD_die(tmp);
00082 #if defined(WIN32) && !defined(__CYGWIN__) && !defined(__MINGW_H)
00083   return 0;
00084 #endif
00085 }

static void register_exit_sched ( void   )  [static]

Definition at line 61 of file BackEnd.C.

References exit_sched().

Referenced by all_init().

00062 {
00063   CkpvInitialize(int,exitSchedHndlr);
00064   CkpvAccess(exitSchedHndlr) = CmiRegisterHandler((CmiHandler)exit_sched);
00065 }

void slave_init ( int  argc,
char **  argv 
)

Definition at line 147 of file BackEnd.C.

References after_backend_init(), all_init(), and master_init().

Referenced by BackEnd::init().

00148 {
00149 #if CMK_SMP
00150   //the original main thread could now be a comm thread
00151   //and a slave thread could now be the main thread,
00152   //so we have to do the master initialization here
00153   if(CmiMyRank()==0){
00154     master_init(argc, argv);
00155     if(CmiMyPe()==0)
00156       after_backend_init(argc, argv);
00157     return;
00158   }
00159 #endif
00160 
00161   all_init(argc, argv);
00162 
00163   if (CkMyRank() < CkMyNodeSize())      // skip the communication thread
00164     CsdScheduler(-1);
00165 }

void topo_getargs ( char **   ) 

Definition at line 90 of file WorkDistrib.C.

References build_ordering(), and randtopo.

Referenced by all_init().

00090                                {
00091   randtopo = CmiGetArgFlag(argv, "+randtopo");
00092   if ( CkMyPe() >= CkNumPes() ) return;
00093   CcdCallOnCondition(CcdTOPOLOGY_AVAIL, (CcdVoidFn)build_ordering, (void*)0);
00094 }


Variable Documentation

Definition at line 50 of file BackEnd.C.

Referenced by BackEnd::exit(), and master_init().

char* gNAMDBinaryName = NULL

Definition at line 237 of file BackEnd.C.

Definition at line 51 of file BackEnd.C.

Referenced by BackEnd::exit(), and master_init().


Generated on 21 Sep 2020 for NAMD by  doxygen 1.6.1