QDP++
qdp_scalar_init.cc
Go to the documentation of this file.
1
7
8
9#include "qdp.h"
10
11#if defined(QDP_USE_QMT_THREADS)
12#include <qmt.h>
13#endif
14
15namespace QDP {
16
17namespace ThreadReductions {
20}
21
23static bool isInit = false;
24
25 extern float pool_size_in_gb;
26
28void QDP_initialize(int *argc, char ***argv)
29{
30 if (isInit)
31 QDP_error_exit("QDP already inited");
32
33 Layout::init(); // setup extremely basic functionality in Layout
34
35 isInit = true;
36
37 //
38 // add qmt inilisisation
39 //
40#ifdef QDP_USE_QMT_THREADS
41
42 // Initialize threads
43 std::cout << "QDP uses qmt threading: Initializing threads..." ;
44 int thread_status = qmt_init();
45 if( thread_status == 0 ) {
46 std::cout << "Success. We have " << qdpNumThreads() << " threads \n";
47 }
48 else {
49 std::cout << "Failure... qmt_init() returned " << thread_status << std::endl;
50 QDP_abort(1);
51 }
52#else
53#ifdef QDP_USE_OMP_THREADS
54 std::cout << "QDP uses OpenMP threading. We have " << qdpNumThreads() << " threads \n";
55#endif
56#endif
57
58
59// Alloc space for reductions
62 std::cout << "Failure... space for norm2 results failed " << std::endl;
63 QDP_abort(1);
64 }
65
68 std::cout << "Failure... space for innerProd results failed " << std::endl;
69 QDP_abort(1);
70 }
71
72 // initialize the global streams
73 QDPIO::cin.init(&std::cin);
74 QDPIO::cout.init(&std::cout);
75 QDPIO::cerr.init(&std::cerr);
76
77 //
78 // Process command line
79 //
81
82 // Look for help
83 bool help_flag = false;
84 for (int i=0; i<*argc; i++)
85 {
86 if (strcmp((*argv)[i], "-h")==0)
87 help_flag = true;
88 }
89
90 if (help_flag)
91 {
92 fprintf(stderr,"Usage: %s options\n",(*argv)[0]);
93 fprintf(stderr,"options:\n");
94 fprintf(stderr," -h help\n");
95#if defined(QDP_USE_PROFILING)
96 fprintf(stderr," -p %%d [%d] profile level\n",
98#endif
99 fprintf(stderr, " -poolsize <X> Create a fixed pool of X GB for Pool Alloc\n");
100 exit(1);
101 }
102
103 for (int i=1; i<*argc; i++)
104 {
105#if defined(QDP_USE_PROFILING)
106 if (strcmp((*argv)[i], "-p")==0)
107 {
108 int lev;
109 sscanf((*argv)[++i], "%d", &lev);
111 }
112#endif
113 if ( strcmp((*argv)[i],"-poolsize")==0)
114 {
115 sscanf((*argv)[++i], "%f", &pool_size_in_gb);
116
117 }
118
119 if (i >= *argc)
120 {
121 QDP_error_exit("missing argument at the end");
122 }
123 }
124
125 initProfile(__FILE__, __func__, __LINE__);
126}
127
129bool QDP_isInitialized() {return isInit;}
130
132void QDP_finalize()
133{
134
135#if defined(QDP_USE_HDF5)
136 H5close();
137#endif
138
139 if ( ThreadReductions::norm2_results != 0x0 ) {
141 }
142
145 }
146
147
148 // finalise qmt
149 //
150#if defined(QMT_USE_QMT_THREADS)
151
152
153
154 // Finalize threads
155 std::cout << "QDP use qmt threading: Finalizing threads" << std::endl;
156 qmt_finalize();
157#endif
158
159 printProfile();
160
161 isInit = false;
162}
163
165void QDP_abort(int status)
166{
167 QDP_finalize();
168 exit(status);
169}
170
172void QDP_resume() {}
173
175void QDP_suspend() {}
176
177
178} // namespace QDP;
double REAL64
void init()
Initializer for layout.
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_error_exit(const char *format,...)
Simple error display and abort routine.
Definition qdp_util.cc:93
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)
float pool_size_in_gb
int qdpNumThreads()
void QDP_finalize()
Turn off the machine.
Primary include file for QDP.