You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ClusterOps is a Python library for managing and executing tasks across CPU and GPU resources in a distributed computing environment. It provides functions for resource discovery, task execution, and performance monitoring.
fromclusteropsimportlist_available_cpusavailable_cpus=list_available_cpus()
print(f"Available CPU cores: {available_cpus}")
execute_on_cpu(cpu_id: int, func: Callable, *args: Any, **kwargs: Any) -> Any
Executes a callable on a specific CPU.
Parameters
Name
Type
Description
cpu_id
int
The CPU core to run the function on.
func
Callable
The function to be executed.
*args
Any
Arguments for the callable.
**kwargs
Any
Keyword arguments for the callable.
Returns
Type
Description
Any
The result of the function execution.
Raises
Exception
Description
ValueError
If the CPU core specified is invalid.
RuntimeError
If there is an error executing the function on the CPU.
Example
fromclusteropsimportexecute_on_cpudefsample_task(n: int) ->int:
returnn*nresult=execute_on_cpu(0, sample_task, 10)
print(f"Result of sample task on CPU 0: {result}")
execute_with_cpu_cores(core_count: int, func: Callable, *args: Any, **kwargs: Any) -> Any
Executes a callable using a specified number of CPU cores.
Parameters
Name
Type
Description
core_count
int
The number of CPU cores to run the function on.
func
Callable
The function to be executed.
*args
Any
Arguments for the callable.
**kwargs
Any
Keyword arguments for the callable.
Returns
Type
Description
Any
The result of the function execution.
Raises
Exception
Description
ValueError
If the number of CPU cores specified is invalid or exceeds available cores.
RuntimeError
If there is an error executing the function on the specified CPU cores.
Example
fromclusteropsimportexecute_with_cpu_coresdefparallel_task(n: int) ->int:
returnsum(range(n))
result=execute_with_cpu_cores(4, parallel_task, 1000000)
print(f"Result of parallel task using 4 CPU cores: {result}")
profile_execution(func: Callable, *args: Any, **kwargs: Any) -> Any
Profiles the execution of a task, collecting metrics like execution time and CPU/GPU usage.
Parameters
Name
Type
Description
func
Callable
The function to profile.
*args
Any
Arguments for the callable.
**kwargs
Any
Keyword arguments for the callable.
Returns
Type
Description
Any
The result of the function execution along with the collected metrics.
Example
fromclusteropsimportprofile_executiondefcpu_intensive_task():
returnsum(i*iforiinrange(10000000))
result=profile_execution(cpu_intensive_task)
print(f"Result of profiled task: {result}")
This API reference provides a comprehensive overview of the ClusterOps library's main functions, their parameters, return values, and usage examples. It should help users understand and utilize the library effectively for managing and executing tasks across CPU and GPU resources in a distributed computing environment.