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 
46 #ifndef NO_SOCKET
47 
48 int send_dgram(const char *host_addr, int port, const char *buf, int buflen) {
49  struct sockaddr_in addr;
50  int sockfd;
51 
52 #ifndef NOHOSTNAME
53  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
54  return -1;
55  }
56 
57  memset(&addr, 0, sizeof(addr));
58  addr.sin_family = AF_INET;
59  addr.sin_port = htons(port);
60  addr.sin_addr.s_addr = inet_addr(host_addr);
61 
62  sendto(sockfd, buf, buflen, 0, (struct sockaddr *)&addr, sizeof(addr));
63 
64  close(sockfd);
65 #endif
66 
67  return 0;
68 }
69 
70 
71 int tbsoft_sendusage(const char *program,
72  const char *versionnum,
73  const char *platform,
74  const char *numcpus,
75  const char *miscinfo) {
76 
77 #ifndef NOHOSTNAME
78 #ifdef TBSOFT_TRACK_HOST
79  iout << iINFO
80  << "Sending usage information to " << TBSOFT_TRACK_HOST
81  << ":" << TBSOFT_TRACK_PORT << " via UDP. Sent data is:\n";
82 #endif
83 
84  char sendbuf[TBSOFT_TRACK_MAXLEN];
85  char host[128];
86  struct passwd *pw;
87  char user[128];
88 
89  memset(sendbuf, 0, sizeof(sendbuf));
90 
91  gethostname(host, 128); host[127] = 0;
92  pw = getpwuid(getuid());
93  if ( pw && pw->pw_name ) {
94  strncpy(user, pw->pw_name, 127); user[127] = 0;
95  } else {
96  sprintf(user,"%d",getuid());
97  }
98 
99  sprintf(sendbuf, "1 %s %s %s %s %s %s %s",
100  program, versionnum, platform, numcpus, miscinfo, host, user);
101  iout << iINFO << sendbuf << "\n" << endi;
102 #ifdef TBSOFT_TRACK_HOST
103  send_dgram(TBSOFT_TRACK_HOST, TBSOFT_TRACK_PORT, sendbuf, strlen(sendbuf));
104 #endif
105 
106 #endif
107  return 0;
108 }
109 
110 #endif
111 
112 extern const char *namd_build_date;
113 extern const char *namd_build_user;
114 extern const char *namd_build_machine;
115 
116 class main : public Chare
117 {
118 public:
119  main(CkArgMsg *msg)
120  {
121 
122  // print banner
123  iout << iINFO << "NAMD " << NAMD_VERSION << " for " << NAMD_PLATFORM
124  << "\n"
125 #ifdef MEM_OPT_VERSION
126  << iWARN << "\n"
127  << iWARN << " *** EXPERIMENTAL MEMORY OPTIMIZED VERSION ***\n"
128  << iWARN << "\n"
129 #endif
130 #if 0
131  << iWARN << "\n"
132  << iWARN << " *** UNRELEASED EXPERIMENTAL VERSION ***\n"
133  << iWARN << "\n"
134 #endif
135 #ifdef SPEC_DISABLED_VERSION
136 
137  << iINFO << "\n"
138  << iINFO << "NAMD is a parallel, object-oriented molecular dynamics\n"
139  << iINFO << "code designed for high-performance simulation of large\n"
140  << iINFO << "biomolecular systems. NAMD is distributed free of\n"
141  << iINFO << "charge and includes source code. For more information\n"
142  << iINFO << "please visit http://www.ks.uiuc.edu/Research/namd/\n"
143  << iINFO << "\n"
144  << iINFO << "*********************************************************\n"
145  << iINFO << "This version of NAMD may be distributed only as a part of\n"
146  << iINFO << "the SPEC Workstation Benchmark and all other distribution\n"
147  << iINFO << "is prohibited. Any use of this software is bound by\n"
148  << iINFO << "the terms of the NAMD License, which is available at\n"
149  << iINFO << "http://www.ks.uiuc.edu/Research/namd/license.html\n"
150  << iINFO << "The NAMD development team will not provide support for\n"
151  << iINFO << "any version of NAMD unless you have first registered\n"
152  << iINFO << "and downloaded the latest version of NAMD available at\n"
153  << iINFO << "http://www.ks.uiuc.edu/Research/namd/\n"
154  << iINFO << "*********************************************************\n"
155 #else
156  << iINFO << "\n"
157  << iINFO << "Please visit http://www.ks.uiuc.edu/Research/namd/\n"
158  << iINFO << "for updates, documentation, and support information.\n"
159 #endif
160 << iINFO << "\n"
161 << iINFO << "Please cite Phillips et al., J. Chem. Phys. 153:044130 (2020) "
162  "doi:10.1063/5.0014475\n"
163 << iINFO << "in all publications reporting results obtained with NAMD.\n"
164 << iINFO << "\n"
165  << endi;
166 
167  char charm_version[64];
168  sprintf(charm_version,"%d",CHARM_VERSION);
169 
170 #if CHARM_VERSION < 60500
171 #error "Charm++ 6.5.1 or later is required to build NAMD"
172 #endif
173 
174  iout << iINFO << "Based on Charm++/Converse " << charm_version
175  << " for " << CMK_MACHINE_NAME << "\n" << endi;
176 
177  iout << iINFO << "Built " << namd_build_date << " by "
178  << namd_build_user << " on " << namd_build_machine << "\n"
179  << endi;
180 #ifndef NO_SOCKET
181  char numcpus[512];
182  sprintf(numcpus,"%d",CkNumPes());
183  tbsoft_sendusage("NAMD",NAMD_VERSION,NAMD_PLATFORM,numcpus,"");
184 #endif
185 
186 #if CMK_BLUEGENE_CHARM
187  iout << iINFO << "Running on BigSim using " << CmiNumPes() << " real processors.\n" << endi;
188 #endif
189  iout << iINFO << "Running on " << CkNumPes() << " processors, "
190  << CmiNumNodes() << " nodes, "
191  << CmiNumPhysicalNodes() << " physical nodes.\n" << endi;
192  iout << iINFO << "CPU topology information " << (CmiCpuTopologyEnabled()?"available":"unavailable") << ".\n" << endi;
193  iout << iINFO << "Charm++/Converse parallel runtime startup completed at "
194  << CmiWallTimer() << " s\n"<< endi;
195  const char* memsource;
196  memusage(&memsource);
197  iout << iINFO << memusage_MB() << " MB of memory in use"
198  << " based on " << memsource << "\n";
199 
200 #if CMK_SMP
201  if ( CmiNumNodes() > 1 && CkNumPes() == CmiNumNodes() ) {
202  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.");
203  }
204 #endif
205  }
206 };
207 
208 #include "main.def.h"
209 
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
const char * namd_build_date
main(CkArgMsg *msg)
Definition: main.C:119
int tbsoft_sendusage(const char *program, const char *versionnum, const char *platform, const char *numcpus, const char *miscinfo)
Definition: main.C:71
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
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:85
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:48
Definition: main.C:116