Decorator API¶
The @cluster decorator is the main interface for Clustrix, allowing you to easily execute functions on remote clusters or locally with parallelization.
- clustrix.decorator.cluster(_func=None, *, cores=None, memory=None, time=None, partition=None, queue=None, parallel=None, environment=None, **kwargs)[source]¶
Decorator to execute functions on a cluster.
Examples¶
Basic Usage¶
from clustrix import cluster
@cluster(cores=4, memory='8GB')
def my_function(x, y):
return x + y
result = my_function(10, 20)
Resource Specification¶
@cluster(
cores=16,
memory='32GB',
time='04:00:00',
partition='gpu'
)
def gpu_computation():
# Your GPU code here
pass
Parallel Loop Execution¶
@cluster(cores=8, parallel=True)
def parallel_processing(data):
results = []
for item in data: # This loop will be parallelized
results.append(expensive_operation(item))
return results
Local Parallelization¶
# Configure for local execution
import clustrix
clustrix.configure(cluster_host=None)
@cluster(cores=8, parallel=True)
def local_parallel_function(data):
# Executes locally using multiprocessing
return [process_item(item) for item in data]