Plain – Parallelism Part 2

Parallel operations (Parallelism) is most often associated with complex math operations. For Plain this is different because we will need it a lot. Imagine my 12 servo robot – it will not be very smooth unless we can operate the servos simultaneously.

Syntax for Parallel (or non-blocking) operation is however a bit hard to create. I have several concepts that will work, but none that I really like and feel is in the spirit of what I want to achieve with Plain.

The first part to control resource usage was easy

use <resource name>[nn]

I need more details, but the array method works well. It tells the system that we need access to several resources of the same type and the name/array gives us a way of manually controlling that resource access if we need to.

This is the way I want Plain to work – easy, automatic and straight forward, but yet manually controllable if you need to.

Parallel operations are more complex in syntax. I need a method to terminate parallel operation, I need a method to synchronize access to the same variables, I need a method to start parallel operations and I need a method to control/query their status – and I want it to be straight forward to use. The way we do distributed processing is an excellent example of Plain.

Parallell
            for x=1 to 20
                        spawn transaction arr[x]
                                   arr[x] = Compute(x)
                        update
            end
end

The syntax above would work – I add an outer mechanism so I can add a “end” that will wait until all parallel operations are completed before it continues. I add spawn to a transaction to specify that this is a background job. What should happen here is that we start 20 jobs.

I lack a way to control/query status + this was not very smooth syntax IMO – but, it the best I got so far. I need to continue work on this.

Luckily the technical side of parallel operations is more straight forward. We will need to create a mini-VM for each job.

Parallell
            for x=1 to 20
                        spawn transaction arr[x]
                                   arr[x] = Compute(x)
                                   on Compute.Error(..)
                                               // todo
                                   end
                        update
            end
end

In this example I add event processing and the ideal way of dong this would be to use 20 VM instances – one instance for each job because we need to maintain integrity as the jobs will process simultaneously. What will happen is that the assembler will create a mini-VM for the code between Spawn..Update – I use the term “mini-VM” to indicate that this is not a full, stand-alone VM. Due to our embedded nature we need to be smart about SRAM usage.

to be continued in part 3

Leave a Reply