QDP++
qdp_parscalarvec_init.cc
Go to the documentation of this file.
1
7
8#include <stdlib.h>
9#include <unistd.h>
10
11#include "qdp.h"
12#include "qmp.h"
13
14namespace QDP {
15
17static bool isInit = false;
18
20void QDP_initialize(int *argc, char ***argv)
21{
22 if (isInit)
23 {
24 QDPIO::cerr << "QDP already inited" << std::endl;
25 QDP_abort(1);
26 }
27
28 //
29 // Process command line
30 //
31
32 // Look for help
33 bool help_flag = false;
34 for (int i=0; i<*argc; i++)
35 {
36 if (strcmp((*argv)[i], "-h")==0)
37 help_flag = true;
38 }
39
40 bool setGeomP = false;
41 multi1d<int> logical_geom(Nd); // apriori logical geometry of the machine
42 logical_geom = 0;
43
44 int rtiP = 0;
45 int QMP_verboseP = 0;
46 const int maxlen = 256;
47 char rtinode[maxlen];
48 strncpy(rtinode, "your_local_food_store", maxlen);
49
50 // Usage
52 if (help_flag)
53 {
54 fprintf(stderr,"Usage: %s options\n",(*argv)[0]);
55 fprintf(stderr,"options:\n");
56 fprintf(stderr," -h help\n");
57 fprintf(stderr," -V %%d [%d] verbose mode for QMP\n",
58 QMP_verboseP);
59#if defined(QDP_USE_PROFILING)
60 fprintf(stderr," -p %%d [%d] profile level\n",
62#endif
63
64 // logical geometry info
65 fprintf(stderr," -geom %%d");
66 for(int i=1; i < Nd; i++)
67 fprintf(stderr," %%d");
68
69 fprintf(stderr," [-1");
70 for(int i=1; i < Nd; i++)
71 fprintf(stderr,",-1");
72 fprintf(stderr,"] logical machine geometry\n");
73
74#ifdef USE_REMOTE_QIO
75 fprintf(stderr," -cd %%s [.] set working dir for QIO interface\n");
76 fprintf(stderr," -rti %%d [%d] use run-time interface\n",
77 rtiP);
78 fprintf(stderr," -rtinode %%s [%s] run-time interface fileserver node\n",
79 rtinode);
80#endif
81
82 QDP_abort(1);
83 }
84
85 for (int i=1; i<*argc; i++)
86 {
87 if (strcmp((*argv)[i], "-V")==0)
88 {
89 QMP_verboseP = 1;
90 }
91#if defined(QDP_USE_PROFILING)
92 else if (strcmp((*argv)[i], "-p")==0)
93 {
94 int lev;
95 sscanf((*argv)[++i], "%d", &lev);
97 }
98#endif
99 else if (strcmp((*argv)[i], "-geom")==0)
100 {
101 setGeomP = true;
102 for(int j=0; j < Nd; j++)
103 {
104 int uu;
105 sscanf((*argv)[++i], "%d", &uu);
106 logical_geom[j] = uu;
107 }
108 }
109#ifdef USE_REMOTE_QIO
110 else if (strcmp((*argv)[i], "-cd")==0)
111 {
112 /* push the dir into the environment vars so qio.c can pick it up */
113 setenv("QHOSTDIR", (*argv)[++i], 0);
114 }
115 else if (strcmp((*argv)[i], "-rti")==0)
116 {
117 sscanf((*argv)[++i], "%d", &rtiP);
118 }
119 else if (strcmp((*argv)[i], "-rtinode")==0)
120 {
121 int n = strlen((*argv)[++i]);
122 if (n >= maxlen)
123 {
124 QDPIO::cerr << "rtinode name too long" << std::endl;
125 QDP_abort(1);
126 }
127 sscanf((*argv)[i], "%s", rtinode);
128 }
129#endif
130#if 0
131 else
132 {
133 QDPIO::cerr << __func__ << ": Unknown argument = " << (*argv)[i] << std::endl;
134 QDP_abort(1);
135 }
136#endif
137
138 if (i >= *argc)
139 {
140 QDPIO::cerr << __func__ << ": missing argument at the end" << std::endl;
141 QDP_abort(1);
142 }
143 }
144
145
146 QMP_verbose (QMP_verboseP);
147
148#if QDP_DEBUG >= 1
149 // Print command line args
150 for (int i=0; i<*argc; i++)
151 QDP_info("QDP_init: arg[%d] = XX%sXX",i,(*argv)[i]);
152#endif
153
154#if QDP_DEBUG >= 1
155 QDP_info("Now initialize QMP");
156#endif
157
158 if (QMP_is_initialized() == QMP_FALSE)
159 {
160 QMP_thread_level_t prv;
161 if (QMP_init_msg_passing(argc, argv, QMP_THREAD_MULTIPLE, &prv) != QMP_SUCCESS)
162 {
163 QDPIO::cerr << "QMP_init_msg_passing failed" << std::endl;
164 QDP_abort(1);
165 }
166 }
167
168#if QDP_DEBUG >= 1
169 QDP_info("QMP inititalized");
170#endif
171
172 if (setGeomP)
173 if (QMP_declare_logical_topology(logical_geom.slice(), Nd) != QMP_SUCCESS)
174 {
175 QDPIO::cerr << "QMP_declare_logical_topology failed" << std::endl;
176 QDP_abort(1);
177 }
178
179#if QDP_DEBUG >= 1
180 QDP_info("Some layout init");
181#endif
182
183 Layout::init(); // setup extremely basic functionality in Layout
184
185 isInit = true;
186
187#if QDP_DEBUG >= 1
188 QDP_info("Init qio");
189#endif
190
191 // initialize the global streams
192 QDPIO::cin.init(&std::cin);
193 QDPIO::cout.init(&std::cout);
194 QDPIO::cerr.init(&std::cerr);
195
196 initProfile(__FILE__, __func__, __LINE__);
197
198 QDPIO::cout << "Initialize done" << std::endl;
199}
200
202bool QDP_isInitialized() {return isInit;}
203
205void QDP_finalize()
206{
207 if ( ! QDP_isInitialized() )
208 {
209 QDPIO::cerr << "QDP is not inited" << std::endl;
210 QDP_abort(1);
211 }
212
213 printProfile();
214
215#if defined(QDP_USE_HDF5)
216 H5close();
217#endif
218
219 QMP_finalize_msg_passing();
220
221 isInit = false;
222}
223
225void QDP_abort(int status)
226{
227 QMP_abort(status);
228}
229
231void QDP_resume() {}
232
234void QDP_suspend() {}
235
236
237} // namespace QDP;
Container for a multi-dimensional 1D array.
Definition qdp_multi.h:25
const T * slice() const
Return ref to a column slice.
Definition qdp_multi.h:225
const int Nd
Definition qdp_params.h:24
void init()
Initializer for layout.
bool primaryNode()
Returns whether this is the primary node.
StandardOutputStream cout
Definition qdp_stdio.cc:21
StandardOutputStream cerr
Definition qdp_stdio.cc:22
StandardInputStream cin
Definition qdp_stdio.cc:20
Yet another random number generator.
void printProfile()
int getProfileLevel()
bool QDP_isInitialized()
Is the machine initialized?
void QDP_initialize(int *argc, char ***argv)
Turn on the machine.
static bool isInit
Private flag for status.
void QDP_suspend()
Suspends QDP communications.
int setProgramProfileLevel(int n)
void QDP_abort(int status)
Panic button.
void QDP_resume()
Resumes QDP communications.
void initProfile(const std::string &file, const std::string &caller, int line)
void QDP_finalize()
Turn off the machine.
int QDP_info(const char *format,...)
Simple information display routine.
Definition qdp_util.cc:43
Primary include file for QDP.
void QMP_verbose(QMP_bool_t verbose)