NAMD
main.C
Go to the documentation of this file.
1 
8 #ifdef WIN32
9 #ifndef NO_SOCKET
10 #define NO_SOCKET
11 #endif
12 #endif
13 
14 #ifndef NO_SOCKET
15 
16 // to track usage, define target host and port in compile line, e.g.:
17 // -DTBSOFT_TRACK_HOST=\"127.0.0.1\" -DTBSOFT_TRACK_PORT=3141
18 // #define TBSOFT_TRACK_HOST "127.0.0.1"
19 // #define TBSOFT_TRACK_PORT 3141
20 
21 #ifndef TBSOFT_TRACK_MAXLEN
22 #define TBSOFT_TRACK_MAXLEN 1024 /* maximum message length */
23 #endif
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <sys/types.h>
29 #include <unistd.h>
30 #include <arpa/inet.h>
31 #include <fcntl.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
34 #include <pwd.h>
35 
36 #endif
37 
38 #include "InfoStream.h"
39 #include "memusage.h"
40 
41 #include "Lattice.h"
42 #include "ComputeMsmMsa.h" // needed for MsmMsaData definition
43 #include "main.decl.h"
44 #include "main.h"
45 #include "NamdEventsProfiling.h"
46 
48  // CkPrintf("########### eventCount: %d #########\n", NamdProfileEvent::EventsCount);
49  for (int i = 0; i < NamdProfileEvent::EventsCount; i++) {
50  // CkPrintf("########### name: %s, id: %d ##########\n", NamdProfileEventStr[i], i);
52  }
53 }
54 
55 #ifndef NO_SOCKET
56 
57 int send_dgram(const char *host_addr, int port, const char *buf, int buflen) {
58  struct sockaddr_in addr;
59  int sockfd;
60 
61 #ifndef NOHOSTNAME
62  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
63  return -1;
64  }
65 
66  memset(&addr, 0, sizeof(addr));
67  addr.sin_family = AF_INET;
68  addr.sin_port = htons(port);
69  addr.sin_addr.s_addr = inet_addr(host_addr);
70 
71  sendto(sockfd, buf, buflen, 0, (struct sockaddr *)&addr, sizeof(addr));
72 
73  close(sockfd);
74 #endif
75 
76  return 0;
77 }
78 
79 
80 int tbsoft_sendusage(const char *program,
81  const char *versionnum,
82  const char *platform,
83  const char *numcpus,
84  const char *miscinfo) {
85 
86 #ifndef NOHOSTNAME
87 #ifdef TBSOFT_TRACK_HOST
88  iout << iINFO
89  << "Sending usage information to " << TBSOFT_TRACK_HOST
90  << ":" << TBSOFT_TRACK_PORT << " via UDP. Sent data is:\n";
91 #endif
92 
93  char sendbuf[TBSOFT_TRACK_MAXLEN];
94  char host[128];
95  struct passwd *pw;
96  char user[128];
97 
98  memset(sendbuf, 0, sizeof(sendbuf));
99 
100  gethostname(host, 128); host[127] = 0;
101  pw = getpwuid(getuid());
102  if ( pw && pw->pw_name ) {
103  strncpy(user, pw->pw_name, 127); user[127] = 0;
104  } else {
105  sprintf(user,"%d",getuid());
106  }
107 
108  sprintf(sendbuf, "1 %s %s %s %s %s %s %s",
109  program, versionnum, platform, numcpus, miscinfo, host, user);
110  iout << iINFO << sendbuf << "\n" << endi;
111 #ifdef TBSOFT_TRACK_HOST
112  send_dgram(TBSOFT_TRACK_HOST, TBSOFT_TRACK_PORT, sendbuf, strlen(sendbuf));
113 #endif
114 
115 #endif
116  return 0;
117 }
118 
119 #endif
120 
121 extern const char *namd_build_date;
122 extern const char *namd_build_user;
123 extern const char *namd_build_machine;
124 
125 class main : public Chare
126 {
127 public:
128  main(CkArgMsg *msg)
129  {
130 
131  // print banner
132  iout << iINFO << "NAMD " << NAMD_VERSION << " for " << NAMD_PLATFORM
133  << "\n"
134 #ifdef MEM_OPT_VERSION
135  << iWARN << "\n"
136  << iWARN << " *** EXPERIMENTAL MEMORY OPTIMIZED VERSION ***\n"
137  << iWARN << "\n"
138 #endif
139 #if 0
140  << iWARN << "\n"
141  << iWARN << " *** UNRELEASED EXPERIMENTAL VERSION ***\n"
142  << iWARN << "\n"
143 #endif
144 #ifdef SPEC_DISABLED_VERSION
145 
146  << iINFO << "\n"
147  << iINFO << "NAMD is a parallel, object-oriented molecular dynamics\n"
148  << iINFO << "code designed for high-performance simulation of large\n"
149  << iINFO << "biomolecular systems. NAMD is distributed free of\n"
150  << iINFO << "charge and includes source code. For more information\n"
151  << iINFO << "please visit http://www.ks.uiuc.edu/Research/namd/\n"
152  << iINFO << "\n"
153  << iINFO << "*********************************************************\n"
154  << iINFO << "This version of NAMD may be distributed only as a part of\n"
155  << iINFO << "the SPEC Workstation Benchmark and all other distribution\n"
156  << iINFO << "is prohibited. Any use of this software is bound by\n"
157  << iINFO << "the terms of the NAMD License, which is available at\n"
158  << iINFO << "http://www.ks.uiuc.edu/Research/namd/license.html\n"
159  << iINFO << "The NAMD development team will not provide support for\n"
160  << iINFO << "any version of NAMD unless you have first registered\n"
161  << iINFO << "and downloaded the latest version of NAMD available at\n"
162  << iINFO << "http://www.ks.uiuc.edu/Research/namd/\n"
163  << iINFO << "*********************************************************\n"
164 #else
165  << iINFO << "\n"
166  << iINFO << "Please visit http://www.ks.uiuc.edu/Research/namd/\n"
167  << iINFO << "for updates, documentation, and support information.\n"
168 #endif
169 << iINFO << "\n"
170 << iINFO << "Please cite Phillips et al., J. Chem. Phys. 153:044130 (2020) "
171  "doi:10.1063/5.0014475\n"
172 << iINFO << "in all publications reporting results obtained with NAMD.\n"
173 << iINFO << "\n"
174  << endi;
175 
176  char charm_version[64];
177  sprintf(charm_version,"%d",CHARM_VERSION);
178 
179 #if CHARM_VERSION < 60500
180 #error "Charm++ 6.5.1 or later is required to build NAMD"
181 #endif
182 
183  iout << iINFO << "Based on Charm++/Converse " << charm_version
184  << " for " << CMK_MACHINE_NAME << "\n" << endi;
185 
186  iout << iINFO << "Built " << namd_build_date << " by "
187  << namd_build_user << " on " << namd_build_machine << "\n"
188  << endi;
189 #ifndef NO_SOCKET
190  char numcpus[512];
191  sprintf(numcpus,"%d",CkNumPes());
192  tbsoft_sendusage("NAMD",NAMD_VERSION,NAMD_PLATFORM,numcpus,"");
193 #endif
194 
195 #if CMK_BLUEGENE_CHARM
196  iout << iINFO << "Running on BigSim using " << CmiNumPes() << " real processors.\n" << endi;
197 #endif
198  iout << iINFO << "Running on " << CkNumPes() << " processors, "
199  << CmiNumNodes() << " nodes, "
200  << CmiNumPhysicalNodes() << " physical nodes.\n" << endi;
201  iout << iINFO << "CPU topology information " << (CmiCpuTopologyEnabled()?"available":"unavailable") << ".\n" << endi;
202  iout << iINFO << "Charm++/Converse parallel runtime startup completed at "
203  << CmiWallTimer() << " s\n"<< endi;
204  const char* memsource;
205  memusage(&memsource);
206  iout << iINFO << memusage_MB() << " MB of memory in use"
207  << " based on " << memsource << "\n";
208 
209 #if 0
210  if ( CmiNumNodes() > 1 && CkNumPes() == CmiNumNodes() ) {
211  NAMD_die("SMP build launched as multiple single-thread processes. Use ++ppn to set number of worker threads per process to match available cores, reserving one core per process for communication thread.");
212  }
213 #endif
214  // Register events marked for profiling
216 
217  // diagnostic information
218 #if 0
219 #ifndef USE_NO_BITFIELDS
220  iout << iINFO << "Using bitfields in atom data structures.\n" << endi;
221 #else
222  iout << iINFO << "Using NO bitfields in atom data structures.\n" << endi;
223 #endif
224  iout << iINFO << " sizeof( CompAtom ) = " << int(sizeof(CompAtom))
225  << "\n"
226  << iINFO << " sizeof( CompAtomExt ) = " << int(sizeof(CompAtomExt))
227  << "\n"
228  << endi;
229 #endif
230  }
231 };
232 
233 #include "main.def.h"
234 
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
const char * namd_build_date
main(CkArgMsg *msg)
Definition: main.C:128
int tbsoft_sendusage(const char *program, const char *versionnum, const char *platform, const char *numcpus, const char *miscinfo)
Definition: main.C:80
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
char const *const NamdProfileEventStr[]
const char * namd_build_machine
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
#define TBSOFT_TRACK_MAXLEN
Definition: main.C:22
double memusage_MB()
Definition: memusage.h:13
const char * namd_build_user
void NAMD_die(const char *err_msg)
Definition: common.C:147
void RegisterNamdEventsProfiling()
Definition: main.C:47
unsigned long memusage(const char **source)
Definition: memusage.C:158
int send_dgram(const char *host_addr, int port, const char *buf, int buflen)
Definition: main.C:57
#define NAMD_REGISTER_EVENT(name, cid)
Definition: main.C:125