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 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   for(tmp=confFile;*tmp;++tmp); // find final null
00109   for( ; tmp != confFile && *tmp != PATHSEP; --tmp); // find last '/'
00110 #if defined(WIN32) && !defined(__CYGWIN__)
00111   if (tmp == confFile) {
00112     // in case this is under cygwin, search for '/' as well
00113     for(tmp=confFile;*tmp;++tmp); // find final null
00114     for( ; tmp != confFile && *tmp != '/'; --tmp); // find last '/'
00115   }
00116 #endif
00117   if ( CHDIR(origcwd) ) NAMD_err(origcwd);
00118   if ( tmp != confFile )
00119   {
00120     *tmp = 0; confFile = tmp + 1;
00121     if ( CHDIR(currentdir) ) NAMD_err(currentdir);
00122     struct stat statBuf;
00123     if (stat(confFile, &statBuf)) {
00124       char buf[1024];
00125       sprintf(buf,"Unable to access config file %s%c%s",currentdir,PATHSEP,confFile);
00126       NAMD_die(buf);
00127     }
00128     iout << iINFO << "Changed directory to " << currentdir << "\n" << endi;
00129     currentdir = GETCWD(currentdir_buf,CWDSIZE);
00130     if ( ! currentdir ) NAMD_err("getcwd after chdir");
00131   }
00132   else{
00133       if ( *tmp == PATHSEP ){ // config file in / is odd, but it might happen
00134           if ( CHDIR(PATHSEPSTR) ) NAMD_err(PATHSEPSTR);
00135           struct stat statBuf;
00136           if (stat(confFile, &statBuf)) {
00137             char buf[1024];
00138             sprintf(buf,"Unable to access config file %s",confFile);
00139             NAMD_die(buf);
00140           }
00141       }else{ // just a config file name, so the path is the current working path
00142           struct stat statBuf;
00143           if (stat(confFile, &statBuf)) {
00144             char buf[1024];
00145             if ( confFile[0] == '-' || confFile[0] == '+' ) {
00146               sprintf(buf,"Unknown command-line option %s",confFile);
00147             } else {
00148               sprintf(buf,"Unable to access config file %s",confFile);
00149             }
00150             NAMD_die(buf);
00151           }
00152           char tmpcurdir[3];
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 94 of file BackEnd.C.

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

Referenced by master_init(), and slave_init().

00095 {
00096 #if defined(WIN32) && !defined(__CYGWIN__) && !defined(__MINGW_H)
00097   _set_new_handler(NAMD_new_handler);
00098 #else
00099   std::set_new_handler(NAMD_new_handler);
00100 #endif
00101   ProcessorPrivateInit();
00102   register_exit_sched();
00103   CmiGetArgFlag(argv, "+idlepoll");  // remove +idlepoll if it's still there
00104   topo_getargs(argv);
00105 #ifdef NAMD_CUDA
00106   cuda_getargs(argv);
00107   argc = CmiGetArgc(argv);
00108 #endif
00109 #ifdef NAMD_MIC
00110   CmiGetArgFlag(argv, "+idlepoll");  // remove +idlepoll if it's still there
00111   mic_getargs(argv);
00112   argc = CmiGetArgc(argv);
00113 #endif
00114   
00115   _initCharm(argc, argv);  // message main Chare
00116 
00117 //#if 0  // moved to WorkDistrib
00118 //#ifdef NAMD_CUDA
00119 //  if ( CkMyPe() < CkNumPes() ) cuda_initialize();
00120 //#endif
00121 //#ifdef NAMD_MIC
00122 //  if ( CkMyPe() < CkNumPes() ) mic_initialize();
00123 //#endif
00124 //#endif
00125 }

CkpvStaticDeclare ( int  ,
exitSchedHndlr   
)

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 151 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().

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

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 131 of file BackEnd.C.

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

Referenced by BackEnd::init().

00132 {
00133 #if CMK_SMP
00134   //the original main thread could now be a comm thread
00135   //and a slave thread could now be the main thread,
00136   //so we have to do the master initialization here
00137   if(CmiMyRank()==0){
00138     master_init(argc, argv);
00139     if(CmiMyPe()==0)
00140       after_backend_init(argc, argv);
00141     return;
00142   }
00143 #endif
00144 
00145   all_init(argc, argv);
00146 
00147   if (CkMyRank() < CkMyNodeSize())      // skip the communication thread
00148     CsdScheduler(-1);
00149 }

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

float cpuTime_start

Definition at line 50 of file BackEnd.C.

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

char* gNAMDBinaryName = NULL

Definition at line 221 of file BackEnd.C.

float wallTime_start

Definition at line 51 of file BackEnd.C.

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


Generated on Sat Sep 23 01:17:16 2017 for NAMD by  doxygen 1.4.7