MCPcopy Create free account
hub / github.com/LBANN/lbann / initialize

Function initialize

src/utils/python.cpp:44–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42} // namespace
43
44void initialize()
45{
46
47 // Thread-safe initialization with double-checked locking pattern
48 if (!is_active()) {
49 static std::mutex m;
50 std::lock_guard<std::mutex> lock(m);
51 if (!is_active()) {
52
53 // Hack to display output from Python
54 // Note: Python outputs didn't appear because MPI intercepts
55 // stdout and stderr. See
56 // https://stackoverflow.com/questions/29352485/python-print-not-working-when-embedded-into-mpi-program
57 Py_UnbufferedStdioFlag = 1;
58
59 // Initialize Python session and release GIL
60 Py_Initialize();
61#if !(PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 7)
62 PyEval_InitThreads();
63#endif
64 init_thread_state = PyEval_SaveThread();
65 if (!is_active()) {
66 LBANN_ERROR("error initializing embedded Python session");
67 }
68 }
69 }
70}
71
72void finalize()
73{

Callers 1

Calls 1

is_activeFunction · 0.85

Tested by

no test coverage detected