?`sá 0111

The Runner — Concurrency

Parallel operations powered by rayon

? Performance Note

Osa uses rayon for true CPU parallelism. Operations on large lists will automatically use multiple threads.

Methods

threads

Osa.threads() ? Int

Get the number of available CPU threads.

ayanmo iye = Osa.threads();
Irosu.fo("Available threads: " + iye);
let count = Osa.threads();
Irosu.println("Available threads: " + count);

sum

Osa.sum(list: List) ? Int

Parallel sum of all numeric elements in a list.

ayanmo awon = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
ayanmo apap? = Osa.sum(awon);
Irosu.fo("Sum: " + apap?);
// Output: Sum: 55
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let total = Osa.sum(numbers);
Irosu.println("Sum: " + total);
// Output: Sum: 55

product

Osa.product(list: List) ? Int

Parallel product of all numeric elements.

ayanmo awon = [1, 2, 3, 4, 5];
ayanmo opolopo = Osa.product(awon);
Irosu.fo("Product: " + opolopo);
// Output: Product: 120
let numbers = [1, 2, 3, 4, 5];
let result = Osa.product(numbers);
Irosu.println("Product: " + result);
// Output: Product: 120

min / max

Osa.min(list: List) ? Int
Osa.max(list: List) ? Int

Find minimum or maximum value in parallel.

ayanmo awon = [5, 2, 8, 1, 9, 3];
ayanmo kekere = Osa.min(awon);
ayanmo tobi = Osa.max(awon);
Irosu.fo("Min: " + kekere + ", Max: " + tobi);
let numbers = [5, 2, 8, 1, 9, 3];
let minimum = Osa.min(numbers);
let maximum = Osa.max(numbers);
Irosu.println("Min: " + minimum + ", Max: " + maximum);

sort

Osa.sort(list: List) ? List

Parallel sort using rayon's parallel sort.

ayanmo awon = [5, 2, 8, 1, 9, 3];
ayanmo tito = Osa.sort(awon);
Irosu.fo("Sorted: " + tito);
// Output: Sorted: [1, 2, 3, 5, 8, 9]
let numbers = [5, 2, 8, 1, 9, 3];
let sorted = Osa.sort(numbers);
Irosu.println("Sorted: " + sorted);
// Output: Sorted: [1, 2, 3, 5, 8, 9]

Complete Example

// Parallel data processing
ayanmo data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

Irosu.fo("Threads: " + Osa.threads());
Irosu.fo("Sum: " + Osa.sum(data));
Irosu.fo("Product: " + Osa.product(data));
Irosu.fo("Min: " + Osa.min(data));
Irosu.fo("Max: " + Osa.max(data));

ayanmo unsorted = [64, 34, 25, 12, 22, 11, 90];
Irosu.fo("Sorted: " + Osa.sort(unsorted));
// Parallel data processing
let data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

Irosu.println("Threads: " + Osa.threads());
Irosu.println("Sum: " + Osa.sum(data));
Irosu.println("Product: " + Osa.product(data));
Irosu.println("Min: " + Osa.min(data));
Irosu.println("Max: " + Osa.max(data));

let unsorted = [64, 34, 25, 12, 22, 11, 90];
Irosu.println("Sorted: " + Osa.sort(unsorted));