Controllers, WitScript and integrations: how a new kind of computation reaches the platform.

OmnibusCloud is a crowdcomputing platform. People connect the idle hours of computers they already own to the groups and projects they choose. A team connects the workstations that stand idle at night; a community gathers the machines of its members. The platform joins the machines, delivers the code they need, hands out the work and collects the results.

Machines are one half of crowdcomputing. The other half is the computation itself, and someone has to write it. Rendering an animation and running a numerical solver have little in common: the programs differ, and so does the way the work can be split. The platform itself contains neither. Every kind of computation arrives as an extension, and an extension can be written by anyone.

This article shows how. It starts from a script of thirteen lines that multiplies two matrices on a group of machines, and opens the C# behind its one distributed call. A second script then shows stages that depend on each other.

The parts

OmnibusCloud is the platform. Its server is the orchestrator: it manages the machines that connect to it and runs the scripts. A job runs on the machines of a private group, assembled by invitation, or of a public project that people choose to join. The owner of each machine decides which of them it serves.

WitEngine is the engine the server is built around. It compiles scripts, keeps track of their data types and calls the operations that controllers expose. It does not know in advance which solvers or data formats will appear.

WitScript is the language a job is written in. A script names the operations and passes data between them. It starts the stages that run on other machines and decides what happens next from the results that come back.

A first script

The Matrices controller in the public repository is a teaching example: dense and sparse matrices, and one operation worth distributing. Its script multiplies two sparse matrices row by row, which is known as Gustavson's algorithm.

witscript
Job:GustavsonMultiplyDistributed(MatrixSparse:matrix1, MatrixSparse:matrix2)
{
    Int:rowCount = Matrix.RowCount(matrix1);
    Int:columnCount = Matrix.ColumnCount(matrix2);
    IntCollection:rowIndices = Int.Range(0, rowCount);
    VectorSparseCollection:rows = Matrix.GetRows(matrix1);

    TupleCollection:tasks = Zip(rowIndices, rows);

    TupleCollection:result = Grid.ForEach(task in tasks) => GustavsonMultiply(task.Item1, task.Item2, matrix2);

    MatrixSparse:resultMatrix = MatrixSparse(rowCount, columnCount, result);
}

A declaration reads Type:name. The first lines run on the server: they count the rows, take them out of the first matrix and pair every row with its index. Grid.ForEach then sends the pairs to the machines of the group, and each machine multiplies its rows by the second matrix with GustavsonMultiply. The last line assembles the returned rows into the product.

The same folder holds this job in a version for the server alone. Its working line is the same except for one word: Transform.ForEach where this one has Grid.ForEach. In a script, that word is the whole difference between one computer and a group.

Behind one operation

GustavsonMultiply is written in C#, like everything in a controller: a controller is a .NET plugin that the engine loads. In the code an operation is called an activity, and it takes two classes. The first describes the call: its name in scripts and its parameters.

csharp
[Activity("GustavsonMultiply")]
[CanRunInParallelOnClient(true)]
public sealed partial class WitActivityMatrixGustavsonMultiply : WitActivityFunction
{
    public IWitReference? Matrix { get; init; }
    public IWitParameter? RowIndex { get; init; }
    public IWitParameter? RowVector { get; init; }
}

The parameters arrive as constants or as references to variables of the script. CanRunInParallelOnClient lets one machine run several such tasks at once.

The second class, the adapter, does the work: it reads the values from the pool of the job's variables, calculates and stores the result. It also answers two questions the orchestrator will ask: how fast is this machine, and how much work does this task hold.

csharp
internal sealed class WitActivityAdapterMatrixGustavsonMultiply
    : WitActivityAdapterFunction<WitActivityMatrixGustavsonMultiply>, IWitBenchmarkAdapter
{
    // The work: one row of the first matrix times the second matrix.
    protected override async Task Process(WitActivityMatrixGustavsonMultiply activity,
        IWitVariablesCollection pool, IWitActivityStatus? activityStatus, WitProcessingStatus status)
    {
        // ... read matrix, rowIndex and vector from the pool ...
        var resultVector = SparseGustavson.MultiplyRowByMatrix(vector, matrix);
        pool.TrySetValue(activity.ReturnReference, new object[] { rowIndex, resultVector.ToArray() });
    }

    // How fast this machine does it, in operations per second.
    public override async Task<IWitBenchmarkResult> RunBenchmark(
        IWitBenchmarkOptions? options, CancellationToken cancellationToken)
    {
        // ... time MultiplyRowByMatrix on a fixed dataset ...
        return new WitBenchmarkResult { Rate = operationsPerSecond, Unit = "gustavson-op@v1" /* ... */ };
    }

    // How much work one task holds, in the same operations.
    protected override double EstimateWork(WitActivityMatrixGustavsonMultiply activity,
        IWitVariablesCollection pool)
    {
        // ... read matrix and vector from the pool ...
        return SparseGustavson.EstimateSparseGustavsonWork(vector, matrix);
    }
}

Both listings are abridged and the comments are added; the full files are the activity and the adapter. A module class registers the pair with the engine and states where the controller runs: on the orchestrator, on the machines, or on both.

An activity can also state what a machine must have. The frame-rendering activity of the Render controller names its operating systems and asks for four gigabytes of memory and ten of temporary storage:

csharp
[RequiresOs(Platform = "Windows,Linux,OSX")]
[RequiresResources(MinRamMb = 4096, MinTempStorageMb = 10240, RequiresLocalAccess = true)]

Only machines that meet such conditions are considered for the task.

In the script above only GustavsonMultiply runs on the machines. The other operations are steps of the script and run on the server, where they prepare the work and assemble the results. One controller usually holds both kinds.

Matrices implements its algorithm itself. A controller can also run an existing program, written in any language. In the same repository Render drives Blender and FFmpeg, and the CalculiX and OpenFOAM controllers run those solvers. The program travels with the controller: a machine needs nothing installed beyond the client, and the client checks what a controller brings against its hash before using it.

The Controller Author Guide walks from a template to a published package.

Unequal machines, ordinary networks

The machines of a group are ordinary computers, possibly in different countries, some on a cable and some on Wi-Fi or a mobile connection. A data centre has ten gigabits between its servers; a group has whatever its members have at home. The machines also differ widely in speed. Distribution has to respect both facts. It uses the network as little as it can, and it gives each machine as much work as that machine can do.

Suppose a job holds 100,000 cases and the group has 50 machines. Grid.ForEach packs the cases into batches, at most one for each machine, and sends every batch in a single transfer. A hundred thousand cases travel as fifty packages or fewer. Fewer, because the orchestrator may leave a slow machine out when its share would finish sooner on faster ones.

The size of a batch comes from the two methods shown above. RunBenchmark says how fast a machine does this kind of work, and EstimateWork says how much work each case holds. Matrices counts both in the same unit, the elementary operations of the multiplication, so any task can be weighed against any machine. A faster machine gets a larger batch, with the aim that all batches end at about the same moment. How close they come depends on the quality of the estimates and on whether the machines stay available. If a machine drops out, its tasks go to the others.

So the benchmark is part of the extension itself. The author of a controller knows best what a unit of work is in the field, and teaches the platform how to measure it.

This strategy is called Balanced, and every controller in the public repository uses it. A second strategy, Queued, lets the machines pull tasks from a common queue. Every task then travels on its own, so the same work costs more network. It is a fallback for the narrow case where the length of a task cannot be estimated, and it is meant mostly for a company's own server. The details are in the Grid controller's README.

How well a computation spreads depends on the ratio of computing to communication. Large independent tasks suit a mixed group of machines well. So do stages that synchronise rarely. For an iterative method the right grain is a property of the method.

When stages depend on each other

The rows of a matrix are independent of each other. Many real computations are harder: the result of one stage decides the input of the next, and the number of stages is not known in advance. PararealSolve from the same repository is such a script. Parareal solves a problem that develops in time. The time span is cut into slices, the slices are computed on different machines at once, and the server corrects their starting points until the whole history is consistent.

witscript
Job:PararealSolve(Blob:model, PararealOptions:opts)
{
    PararealPlan:plan = Parareal.Slice(model, opts);
    PararealState:state = Parareal.Init(model, plan);
    Int:maxIter = Parareal.IterationBudget(opts);
    PararealTaskCollection:tasks;
    PararealResultCollection:wave;
    Bool:converged = false;

    Loop(maxIter)
    {
        tasks = Parareal.MakeTasks(plan, state);
        wave = Grid.ForEach(task in tasks) => Parareal.Propagate(task);
        state = Parareal.Correct(plan, state, wave);
        converged = Parareal.IsConverged(state);
        If(converged) { Break; }
    }

    ~ deferred snapshot wave: recompute from converged states, snapshots on ~
    tasks = Parareal.MakeSnapshotTasks(plan, state);
    wave = Grid.ForEach(task in tasks) => Parareal.Propagate(task);
    Blob:timeline = Parareal.Collect(plan, wave, state);
    Return(timeline);
}

The script builds a plan and an initial state. Inside the loop it makes a collection of tasks from the current state, and Grid.ForEach spreads the calls of Parareal.Propagate over the machines. When that wave has returned, Parareal.Correct updates the state and Parareal.IsConverged decides whether another wave is needed. The loop stops at convergence or when the iteration budget runs out. One more wave then computes the snapshots, and Parareal.Collect assembles the timeline. The line between tildes is a comment.

Two controllers work here. Parareal supplies the mathematics and Grid supplies the distribution. Parareal.Propagate is the only operation here that leaves the server; the rest are steps of the script itself. The order of events lives in the script and can change without touching either controller. How finely the work can be cut still depends on the method.

Nothing in the script names a machine. The job is written as if for one computer, and each task still runs whole on one machine of the group. Many machines addressed as one computer: this is the idea behind what OmnibusCloud calls the ultracomputer.

Results from machines you do not own

A team trusts the machines of its own group. A public project gathers machines of people its author has never met, and has to check what comes back. Grid.Replicas builds the options for that:

witscript
ProcessingOptions:checked = Grid.Replicas(2, 0.05);
results = Grid.ForEach(item in items, checked) => Transformer(item);

Here five per cent of the items run twice, each time on a different machine. The platform picks them at random, so a machine cannot tell whether its task is also running somewhere else. Comparing the copies is left to the controller, which knows when two answers in its field count as equal. The copies are extra work, so the script's author chooses how large a share to check.

Who writes what

So far one person could have written everything above. Nothing requires that.

You write It adds Example
A controller Data types and operations Running a solver, rendering a frame
A script A job composed of operations that already exist A parameter study, an iterative solver
An integration A way to start a job from an application A Blender add-on, a plugin for ParaView

The author of a controller may know a numerical method deeply and nothing about user interfaces. Someone else arranges the operations of that controller into scripts, changing the order of stages or adding iterations. A third person writes the integration: it takes data from an application, hands it to a script as a job and brings the results back to where the user works. These people do not have to meet.

A Blender add-on is such an integration for an artist, and WitSweep is one for an engineer with a parameter study. One controller can serve several applications. They connect through the .NET SDK or through the native SDK with bindings for C++ and Python. The Blender integration is an open example, and the author guide explains how a controller publishes its data contracts for clients outside .NET.

How a controller reaches the machines

A controller is packed together with its manifest, which lists what it needs and the data it brings: the packaging tool. Once it is published on a server, the machines that can run it receive it without anyone installing anything by hand. They run its benchmark, and the results guide the distribution of work from then on.

We publish every controller that runs on the public OmnibusCloud, and the source of each is in the public repository. Anyone can read what will run on a machine before connecting it.

A controller written by someone else can join them on the same terms. It is open source in a public repository, and we review it before it is published. A review is not a promise to publish.

A company that runs a server of its own installs controller packages through the admin interface, and what runs there is decided by its administrator.

Scripts are published separately. One set of controllers serves many scripts, and a new script needs no change in its controllers when the operations it calls already exist. The two are versioned separately as well: a script package declares the range of controller versions it works with, and a mismatch shows up when the packages are restored, before anything runs (the decision record).

Try it on your own computer

OutWit.Engine.Sdk on NuGet is a local stand-in for WitEngine and the OmnibusCloud server, made for tests. It compiles WitScript with the same parser and loads the same controllers, but it has no network part: the tasks that Grid.ForEach would send to a group run side by side on the local machine. A controller can thus be tried under realistic conditions before any server is involved, with limits on the size and duration of a job. The tests in the repository are built on it.

shell
git clone https://github.com/OmnibusCloud/Controllers
cd Controllers
dotnet test Special/OutWit.Controller.Special.Tests
dotnet test Matrices/OutWit.Controller.Matrices.Tests

The repository needs the .NET 10 SDK. A first exercise is the LoopTest method in the tests of the Special controller. It compiles a job with Loop(3) and Trace, runs it through the SDK and checks the outcome. Run it, add another Trace call to the script and correct the expected result. ProcessingLoopTest in the Matrices tests goes one step further: it runs the server-only script from this article and compares the product with a reference library. The testing section of the author guide describes the setups.

What a local run cannot show is the cost of moving data and the behaviour of machines that differ in speed or leave in the middle of a job. That is learned on a real group.

The next step depends on what you have. It may be a script composed of existing operations, or a new operation written by the guide. A new controller is needed only when the work calls for a capability that no existing controller has.

What else can run here

Delivering controllers, choosing the machines that can run them, balancing the work, running scripts with distributed stages: these mechanisms stay the same from one field to the next. The operations and the scripts change, and they can be anyone's.

The public repository covers rendering, engineering parameter studies, distributed numerical methods and scientific visualisation. Work of the same shape exists far beyond them. A few places where it does:

  • Evaluating AI models. Checking the programs a model has written against tests is a batch of independent runs, one program per task. Scoring a model on a large benchmark has the same shape.
  • Preparing training data. A large corpus or image set is cut into pieces, each piece is cleaned or checked on its own, and the results are merged.
  • Search and sampling. A hyperparameter sweep or a Monte Carlo study is many runs of one program with different numbers.
  • Testing software. Mutation testing and fuzzing consist of a great many short runs that do not depend on each other.
  • Research computing. Molecular docking, sequence analysis, image processing for a telescope or a microscope: the classic work of volunteer computing.

The list has no end, because the field matters less than the shape of the work. Any computation fits when it divides into pieces that each run whole on one machine, and when moving the data of a piece takes far less time than computing it. Every controller written for such work adds one more thing the ultracomputer can do.

What is open and what is not

The controllers and tools in the public repository are under the MIT licence. So are the client SDKs, OutWit.Cloud.SDK for .NET and OutWit.Cloud.SDK.Native for other languages. They are the door into OmnibusCloud through which an application starts jobs and takes the results back, and they are meant for any use, commercial included.

The engine SDK, OutWit.Engine.Sdk, is a different thing: a local stand-in for WitEngine and the OmnibusCloud server, used to test controllers and scripts. It is not part of a working installation, and no controller depends on it. It is free under a non-commercial licence, for personal, educational and research use.

The engine and the server are not open. The programs that controllers bring keep their own licences.

Where to start

The path for a new kind of work is short to describe. Write it and test it on your own computer with the SDK, keep it in a public repository, and open an issue. After a review it can be published on the public OmnibusCloud, and from then on a group or a project can run it.

The Controllers repository is the place to read the code and to ask: questions and proposals go to its Issues. To start a technical conversation, describe what goes in and what should come out, and the shape of the computation: which parts can run independently and which wait for earlier results, and how much data moves between them.

A contribution can be small: an example script, a reproducible test, a fix in the documentation, a description of a workload that needs a controller of its own.

This is the first part of a series. The next part opens a controller from its folder to its data types, in the order an author writes it.

Blender is developed by the Blender Foundation. ParaView is developed by Kitware. OpenFOAMĀ® is a registered trademark of OpenCFD Limited. OmnibusCloud is not affiliated with or endorsed by any of them.