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 extern const char *namd_commit_id;
125 
126 class main : public Chare
127 {
128 public:
129  main(CkArgMsg *msg)
130  {
131 
132  // print banner
133  iout << iINFO << "NAMD " << NAMD_VERSION << " for " << NAMD_PLATFORM
134  << "\n"
135 #ifdef MEM_OPT_VERSION
136  << iWARN << "\n"
137  << iWARN << " *** EXPERIMENTAL MEMORY OPTIMIZED VERSION ***\n"
138  << iWARN << "\n"
139 #endif
140 #if 0
141  << iWARN << "\n"
142  << iWARN << " *** UNRELEASED EXPERIMENTAL VERSION ***\n"
143  << iWARN << "\n"
144 #endif
145 #ifdef SPEC_DISABLED_VERSION
146 
147  << iINFO << "\n"
148  << iINFO << "NAMD is a parallel, object-oriented molecular dynamics\n"
149  << iINFO << "code designed for high-performance simulation of large\n"
150  << iINFO << "biomolecular systems. NAMD is distributed free of\n"
151  << iINFO << "charge and includes source code. For more information\n"
152  << iINFO << "please visit http://www.ks.uiuc.edu/Research/namd/\n"
153  << iINFO << "\n"
154  << iINFO << "*********************************************************\n"
155  << iINFO << "This version of NAMD may be distributed only as a part of\n"
156  << iINFO << "the SPEC Workstation Benchmark and all other distribution\n"
157  << iINFO << "is prohibited. Any use of this software is bound by\n"
158  << iINFO << "the terms of the NAMD License, which is available at\n"
159  << iINFO << "http://www.ks.uiuc.edu/Research/namd/license.html\n"
160  << iINFO << "The NAMD development team will not provide support for\n"
161  << iINFO << "any version of NAMD unless you have first registered\n"
162  << iINFO << "and downloaded the latest version of NAMD available at\n"
163  << iINFO << "http://www.ks.uiuc.edu/Research/namd/\n"
164  << iINFO << "*********************************************************\n"
165 #else
166  << iINFO << "\n"
167  << iINFO << "Please visit http://www.ks.uiuc.edu/Research/namd/\n"
168  << iINFO << "for updates, documentation, and support information.\n"
169 #endif
170 << iINFO << "\n"
171 << iINFO << "Please cite Phillips et al., J. Chem. Phys. 153:044130 (2020) "
172  "doi:10.1063/5.0014475\n"
173 << iINFO << "in all publications reporting results obtained with NAMD.\n"
174 << iINFO << "\n"
175  << endi;
176 
177  char charm_version[64];
178  sprintf(charm_version,"%d",CHARM_VERSION);
179 
180 #if CHARM_VERSION < 60500
181 #error "Charm++ 6.5.1 or later is required to build NAMD"
182 #endif
183 
184  iout << iINFO << "Based on Charm++/Converse " << charm_version
185  << " for " << CMK_MACHINE_NAME << "\n" << endi;
186 
187  iout << iINFO << "Built " << namd_build_date << " by "
188  << namd_build_user << " on " << namd_build_machine << "\n"
189  << endi;
190 
191  if (strlen(namd_commit_id) > 0) {
192  iout << iINFO << "Source code at Git commit ID "
193  << namd_commit_id << "\n"
194  << endi;
195  }
196 
197 #ifndef NO_SOCKET
198  char numcpus[512];
199  sprintf(numcpus,"%d",CkNumPes());
200  tbsoft_sendusage("NAMD",NAMD_VERSION,NAMD_PLATFORM,numcpus,"");
201 #endif
202 
203 #if CMK_BLUEGENE_CHARM
204  iout << iINFO << "Running on BigSim using " << CmiNumPes() << " real processors.\n" << endi;
205 #endif
206  iout << iINFO << "Running on " << CkNumPes() << " processors, "
207  << CmiNumNodes() << " nodes, "
208  << CmiNumPhysicalNodes() << " physical nodes.\n" << endi;
209  iout << iINFO << "CPU topology information " << (CmiCpuTopologyEnabled()?"available":"unavailable") << ".\n" << endi;
210  iout << iINFO << "Charm++/Converse parallel runtime startup completed at "
211  << CmiWallTimer() << " s\n"<< endi;
212  const char* memsource;
213  memusage(&memsource);
214  iout << iINFO << memusage_MB() << " MB of memory in use"
215  << " based on " << memsource << "\n";
216 
217 #if 0
218  if ( CmiNumNodes() > 1 && CkNumPes() == CmiNumNodes() ) {
219  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.");
220  }
221 #endif
222  // Register events marked for profiling
224 
225  // diagnostic information
226 #if 0
227 #ifndef USE_NO_BITFIELDS
228  iout << iINFO << "Using bitfields in atom data structures.\n" << endi;
229 #else
230  iout << iINFO << "Using NO bitfields in atom data structures.\n" << endi;
231 #endif
232  iout << iINFO << " sizeof( CompAtom ) = " << int(sizeof(CompAtom))
233  << "\n"
234  << iINFO << " sizeof( CompAtomExt ) = " << int(sizeof(CompAtomExt))
235  << "\n"
236  << endi;
237 #endif
238  }
239 };
240 
241 #include "main.def.h"
242 
const char * namd_commit_id
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
const char * namd_build_date
main(CkArgMsg *msg)
Definition: main.C:129
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:126