turbine_code turbine_run_string(MPI_Comm comm, const char* script, int argc, const char** argv, char* output, Tcl_Interp* interp) { bool created_interp = false; if (interp == NULL) { // Create Tcl interpreter: interp = Tcl_CreateInterp(); Tcl_Init(interp); created_interp = true; } if (comm != MPI_COMM_NULL) { // Store communicator pointer in Tcl variable for turbine::init MPI_Comm* comm_ptr = &comm; Tcl_Obj* TURBINE_ADLB_COMM = Tcl_NewStringObj("TURBINE_ADLB_COMM", -1); Tcl_Obj* adlb_comm_ptr = Tcl_NewLongObj((long) comm_ptr); Tcl_ObjSetVar2(interp, TURBINE_ADLB_COMM, NULL, adlb_comm_ptr, 0); } // Render argc/argv for Tcl turbine_tcl_set_integer(interp, "argc", argc); Tcl_Obj* argv_obj = Tcl_NewStringObj("argv", -1); Tcl_Obj* argv_val_obj; if (argc > 0) argv_val_obj = turbine_tcl_list_new(argc, argv); else argv_val_obj = Tcl_NewStringObj("", 0); Tcl_ObjSetVar2(interp, argv_obj, NULL, argv_val_obj, 0); if (output != NULL) turbine_tcl_set_wideint(interp, "turbine_run_output", (ptrdiff_t) output); // Run the user script int rc = Tcl_Eval(interp, script); // Check for errors if (rc != TCL_OK) { Tcl_Obj* error_dict = Tcl_GetReturnOptions(interp, rc); Tcl_Obj* error_info = Tcl_NewStringObj("-errorinfo", -1); Tcl_Obj* error_msg; Tcl_DictObjGet(interp, error_dict, error_info, &error_msg); char* msg_string = Tcl_GetString(error_msg); printf("turbine_run(): Tcl error: %s\n", msg_string); return TURBINE_ERROR_UNKNOWN; } if (created_interp) { // Clean up Tcl_DeleteInterp(interp); } return TURBINE_SUCCESS; }
static void set_namespace_constants(Tcl_Interp* interp) { turbine_tcl_set_integer(interp, "::turbine::WORK", TURBINE_ADLB_WORK_TYPE_WORK); // Map control to work for backwards compatibility with Tcl code // that distinguishes between the two turbine_tcl_set_integer(interp, "::turbine::CONTROL", TURBINE_ADLB_WORK_TYPE_WORK); turbine_tcl_set_integer(interp, "::turbine::LOCAL", TURBINE_ADLB_WORK_TYPE_LOCAL); turbine_tcl_set_string(interp, "::turbine::NOOP_EXEC_NAME", NOOP_EXECUTOR_NAME); #if HAVE_COASTER == 1 turbine_tcl_set_string(interp, "::turbine::COASTER_EXEC_NAME", COASTER_EXECUTOR_NAME); #endif }