def c_extension_link(in_queue, out_queue): # type: (..., ...) -> None """ Main C extension process. :param in_queue: Queue to receive messages. :param out_queue: Queue to send messages. :return: None """ import compss alive = True while alive: message = in_queue.get() command = message[0] parameters = [] if len(message) > 0: parameters = message[1:] if command == START: compss.start_runtime() elif command == SET_DEBUG: compss.set_debug(*parameters) elif command == STOP: compss.stop_runtime(*parameters) alive = False elif command == CANCEL_TASKS: compss.cancel_application_tasks(*parameters) elif command == ACCESSED_FILE: accessed = compss.accessed_file(*parameters) out_queue.put(accessed) elif command == OPEN_FILE: compss_name = compss.open_file(*parameters) out_queue.put(compss_name) elif command == CLOSE_FILE: compss.close_file(*parameters) elif command == DELETE_FILE: result = compss.delete_file(*parameters) out_queue.put(result) elif command == GET_FILE: compss.get_file(*parameters) elif command == GET_DIRECTORY: compss.get_directory(*parameters) elif command == BARRIER: compss.barrier(*parameters) elif command == BARRIER_GROUP: exception_message = compss.barrier_group(*parameters) out_queue.put(exception_message) elif command == OPEN_TASK_GROUP: compss.open_task_group(*parameters) elif command == CLOSE_TASK_GROUP: compss.close_task_group(*parameters) elif command == GET_LOGGING_PATH: log_path = compss.get_logging_path() out_queue.put(log_path) elif command == GET_NUMBER_OF_RESOURCES: num_resources = compss.get_number_of_resources(*parameters) out_queue.put(num_resources) elif command == REQUEST_RESOURCES: compss.request_resources(*parameters) elif command == FREE_RESOURCES: compss.free_resources(*parameters) elif command == REGISTER_CORE_ELEMENT: compss.register_core_element(*parameters) elif command == PROCESS_TASK: compss.process_task(*parameters) elif command == SET_PIPES: compss.set_pipes(*parameters) else: raise Exception("Unknown link command")
def c_extension_link(in_queue, out_queue, redirect_std, out_file_name, err_file_name): # type: (Queue, Queue, bool, str, str) -> None """ Main C extension process. :param in_queue: Queue to receive messages. :param out_queue: Queue to send messages. :param redirect_std: Decide whether to store the stdout and stderr into files or not. :param out_file_name: File where to store the stdout (only required if redirect_std is True). :param err_file_name: File where to store the stderr (only required if redirect_std is True). :return: None """ # Import C extension within the external process import compss with ipython_std_redirector(out_file_name, err_file_name) \ if redirect_std else not_std_redirector(): alive = True while alive: message = in_queue.get() command = message[0] parameters = [] # type: list if len(message) > 0: parameters = list(message[1:]) if command == START: compss.start_runtime() elif command == SET_DEBUG: compss.set_debug(*parameters) elif command == STOP: compss.stop_runtime(*parameters) alive = False elif command == CANCEL_TASKS: compss.cancel_application_tasks(*parameters) elif command == ACCESSED_FILE: accessed = compss.accessed_file(*parameters) out_queue.put(accessed) elif command == OPEN_FILE: compss_name = compss.open_file(*parameters) out_queue.put(compss_name) elif command == CLOSE_FILE: compss.close_file(*parameters) elif command == DELETE_FILE: result = compss.delete_file(*parameters) out_queue.put(result) elif command == GET_FILE: compss.get_file(*parameters) elif command == GET_DIRECTORY: compss.get_directory(*parameters) elif command == BARRIER: compss.barrier(*parameters) elif command == BARRIER_GROUP: exception_message = compss.barrier_group(*parameters) out_queue.put(exception_message) elif command == OPEN_TASK_GROUP: compss.open_task_group(*parameters) elif command == CLOSE_TASK_GROUP: compss.close_task_group(*parameters) elif command == GET_LOGGING_PATH: log_path = compss.get_logging_path() out_queue.put(log_path) elif command == GET_NUMBER_OF_RESOURCES: num_resources = compss.get_number_of_resources(*parameters) out_queue.put(num_resources) elif command == REQUEST_RESOURCES: compss.request_resources(*parameters) elif command == FREE_RESOURCES: compss.free_resources(*parameters) elif command == REGISTER_CORE_ELEMENT: compss.register_core_element(*parameters) elif command == PROCESS_TASK: compss.process_task(*parameters) elif command == PROCESS_HTTP_TASK: compss.process_http_task(*parameters) elif command == SET_PIPES: compss.set_pipes(*parameters) elif command == READ_PIPES: compss.read_pipes(*parameters) elif command == SET_WALL_CLOCK: compss.set_wall_clock(*parameters) else: raise PyCOMPSsException("Unknown link command")
def register_ce(core_element): """ Calls the external python library (that calls the bindings-common) in order to notify the runtime about a core element that needs to be registered. Java Examples: // METHOD System.out.println('Registering METHOD implementation'); String core_elementSignature = 'methodClass.methodName'; String impl_signature = 'methodClass.methodName'; String impl_constraints = 'ComputingUnits:2'; String impl_type = 'METHOD'; String[] impl_type_args = new String[] { 'methodClass', 'methodName' }; rt.registerCoreElement(coreElementSignature, impl_signature, impl_constraints, impl_type, impl_type_args); // MPI System.out.println('Registering MPI implementation'); core_elementSignature = 'methodClass1.methodName1'; impl_signature = 'mpi.MPI'; impl_constraints = 'StorageType:SSD'; impl_type = 'MPI'; impl_type_args = new String[] { 'mpiBinary', 'mpiWorkingDir', 'mpiRunner' }; rt.registerCoreElement(coreElementSignature, impl_signature, impl_constraints, impl_type, impl_type_args); // BINARY System.out.println('Registering BINARY implementation'); core_elementSignature = 'methodClass2.methodName2'; impl_signature = 'binary.BINARY'; impl_constraints = 'MemoryType:RAM'; impl_type = 'BINARY'; impl_type_args = new String[] { 'binary', 'binaryWorkingDir' }; rt.registerCoreElement(coreElementSignature, impl_signature, impl_constraints, impl_type, impl_type_args); // OMPSS System.out.println('Registering OMPSS implementation'); core_elementSignature = 'methodClass3.methodName3'; impl_signature = 'ompss.OMPSS'; impl_constraints = 'ComputingUnits:3'; impl_type = 'OMPSS'; impl_type_args = new String[] { 'ompssBinary', 'ompssWorkingDir' }; rt.registerCoreElement(coreElementSignature, impl_signature, impl_constraints, impl_type, impl_type_args); // OPENCL System.out.println('Registering OPENCL implementation'); core_elementSignature = 'methodClass4.methodName4'; impl_signature = 'opencl.OPENCL'; impl_constraints = 'ComputingUnits:4'; impl_type = 'OPENCL'; impl_type_args = new String[] { 'openclKernel', 'openclWorkingDir' }; rt.registerCoreElement(coreElementSignature, impl_signature, impl_constraints, impl_type, impl_type_args); // VERSIONING System.out.println('Registering METHOD implementation'); core_elementSignature = 'methodClass.methodName'; impl_signature = 'anotherClass.anotherMethodName'; impl_constraints = 'ComputingUnits:1'; impl_type = 'METHOD'; impl_type_args = new String[] { 'anotherClass', 'anotherMethodName' }; rt.registerCoreElement(coreElementSignature, impl_signature, impl_constraints, impl_type, impl_type_args); --------------------- Core Element fields: ce_signature: <String> Core Element signature (e.g.- 'methodClass.methodName') impl_signature: <String> Implementation signature (e.g.- 'methodClass.methodName') impl_constraints: <Dict> Implementation constraints (e.g.- '{ComputingUnits:2}') impl_type: <String> Implementation type ('METHOD' | 'MPI' | 'BINARY' | 'OMPSS' | 'OPENCL') impl_type_args: <List(Strings)> Implementation arguments (e.g.- ['methodClass', 'methodName']) :param core_element: <CE> Core Element to register :return: """ # Retrieve Core element fields ce_signature = core_element.get_ce_signature() impl_signature = core_element.get_impl_signature() impl_constraints = core_element.get_impl_constraints() impl_type = core_element.get_impl_type() impl_type_args = core_element.get_impl_type_args() if __debug__: logger.debug("Registering CE with signature: %s" % ce_signature) logger.debug("\t - Implementation signature: %s" % impl_signature) # Build constraints string from constraints dictionary impl_constraints_string = '' for key, value in impl_constraints.items(): if isinstance(value, list): val = str(value).replace('\'', '') impl_constraints_string += key + ':' + str(val) + ';' else: impl_constraints_string += key + ':' + str(value) + ';' if __debug__: logger.debug("\t - Implementation constraints: %s" % impl_constraints_string) logger.debug("\t - Implementation type: %s" % impl_type) impl_type_args_string = ' '.join(impl_type_args) if __debug__: logger.debug("\t - Implementation type arguments: %s" % impl_type_args_string) # Call runtime with the appropriate parameters compss.register_core_element(ce_signature, impl_signature, impl_constraints_string, impl_type, impl_type_args) if __debug__: logger.debug("CE with signature %s registered." % ce_signature)