Skip to content

Commit e7fb18b

Browse files
committed
WIP (ref #153)
1 parent 80812e4 commit e7fb18b

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

turbine/code/src/tcl/python/tcl-python.c

+9-17
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
#include <dlfcn.h>
3737

3838
#include <stdio.h>
39+
#include <stdlib.h>
3940

41+
#include <mpi.h>
4042
#include <tcl.h>
4143

4244
#include "src/util/debug.h"
@@ -107,6 +109,7 @@ python_init(void)
107109

108110
if (initialized) return TCL_OK;
109111
DEBUG_TCL_TURBINE("python: initializing...");
112+
printf("python: initializing...\n");
110113
Py_InitializeEx(1);
111114
main_module = PyImport_AddModule("__main__");
112115
if (main_module == NULL) return handle_python_exception(true);
@@ -151,11 +154,13 @@ python_eval(bool persist, bool exceptions_are_errors,
151154

152155
// Execute code:
153156
DEBUG_TCL_TURBINE("python: code: %s", code);
157+
printf("python: code: %s\n", code); fflush(stdout);
154158
PyRun_String(code, Py_file_input, main_dict, local_dict);
155159
if (PyErr_Occurred()) EXCEPTION(exceptions_are_errors);
156160

157161
// Evaluate expression:
158162
DEBUG_TCL_TURBINE("python: expr: %s", expr);
163+
printf("python: expr: %s\n", expr); fflush(stdout);
159164
PyObject* o = PyRun_String(expr, Py_eval_input,
160165
main_dict, local_dict);
161166
if (o == NULL) EXCEPTION(exceptions_are_errors);
@@ -216,24 +221,15 @@ python_parallel_persist(MPI_Comm comm, char* code, char* expr)
216221
printf("code: %s\n", code);
217222
printf("expr: %s\n", expr);
218223

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);
219228

220229
int rc;
221230
rc = python_init();
222231
assert(rc == TCL_OK);
223232

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();
237233
char* output;
238234
rc = python_eval(true, true, code, expr, &output);
239235
if (rc != TCL_OK)
@@ -244,13 +240,9 @@ python_parallel_persist(MPI_Comm comm, char* code, char* expr)
244240

245241
printf("eval ok.\n"); fflush(stdout);
246242

247-
// Py_DECREF(task_comm);
248-
// Py_DECREF(globals);
249243
MPI_Comm_free(&comm);
250244
if (task_rank == 0)
251-
// Return a real value
252245
return output;
253-
// Return a placeholder
254246
free(output);
255247
return NULL;
256248
}

0 commit comments

Comments
 (0)