36
36
#include <dlfcn.h>
37
37
38
38
#include <stdio.h>
39
+ #include <stdlib.h>
39
40
41
+ #include <mpi.h>
40
42
#include <tcl.h>
41
43
42
44
#include "src/util/debug.h"
@@ -107,6 +109,7 @@ python_init(void)
107
109
108
110
if (initialized ) return TCL_OK ;
109
111
DEBUG_TCL_TURBINE ("python: initializing..." );
112
+ printf ("python: initializing...\n" );
110
113
Py_InitializeEx (1 );
111
114
main_module = PyImport_AddModule ("__main__" );
112
115
if (main_module == NULL ) return handle_python_exception (true);
@@ -151,11 +154,13 @@ python_eval(bool persist, bool exceptions_are_errors,
151
154
152
155
// Execute code:
153
156
DEBUG_TCL_TURBINE ("python: code: %s" , code );
157
+ printf ("python: code: %s\n" , code ); fflush (stdout );
154
158
PyRun_String (code , Py_file_input , main_dict , local_dict );
155
159
if (PyErr_Occurred ()) EXCEPTION (exceptions_are_errors );
156
160
157
161
// Evaluate expression:
158
162
DEBUG_TCL_TURBINE ("python: expr: %s" , expr );
163
+ printf ("python: expr: %s\n" , expr ); fflush (stdout );
159
164
PyObject * o = PyRun_String (expr , Py_eval_input ,
160
165
main_dict , local_dict );
161
166
if (o == NULL ) EXCEPTION (exceptions_are_errors );
@@ -216,24 +221,15 @@ python_parallel_persist(MPI_Comm comm, char* code, char* expr)
216
221
printf ("code: %s\n" , code );
217
222
printf ("expr: %s\n" , expr );
218
223
224
+ long long int task_comm_int = (long long int ) comm ;
225
+ char task_comm_string [64 ];
226
+ sprintf (task_comm_string , "%lli" , task_comm_int );
227
+ setenv ("task_comm" , task_comm_string , true);
219
228
220
229
int rc ;
221
230
rc = python_init ();
222
231
assert (rc == TCL_OK );
223
232
224
- PyRun_String ("print(\"warmup\")" , Py_file_input , main_dict , local_dict );
225
- if (PyErr_Occurred ()) { printf ("ERROR\n" ); }
226
- printf ("warmup ok.\n" ); fflush (stdout );
227
-
228
- long long int task_comm_int = (long long int ) comm ;
229
- PyObject * globals = PyEval_GetGlobals ();
230
- PyObject * key = PyBytes_FromString ("task_comm" );
231
- PyObject * task_comm = PyLong_FromLong (task_comm_int );
232
- PyObject_SetItem (globals , key , task_comm );
233
-
234
- printf ("comm ok.\n" ); fflush (stdout );
235
-
236
- // PyObject* globals = PyEval_GetGlobals();
237
233
char * output ;
238
234
rc = python_eval (true, true, code , expr , & output );
239
235
if (rc != TCL_OK )
@@ -244,13 +240,9 @@ python_parallel_persist(MPI_Comm comm, char* code, char* expr)
244
240
245
241
printf ("eval ok.\n" ); fflush (stdout );
246
242
247
- // Py_DECREF(task_comm);
248
- // Py_DECREF(globals);
249
243
MPI_Comm_free (& comm );
250
244
if (task_rank == 0 )
251
- // Return a real value
252
245
return output ;
253
- // Return a placeholder
254
246
free (output );
255
247
return NULL ;
256
248
}
0 commit comments