PGA - ProGram Algebra

# Parallel Simulator

The parallel simulator is a controller that can start several simulators that work on one core of the basic instruction set, so that the programs can interact.

The following demonstrations give some insight in the use of the parallel simulator.

## Interacting programs

We use three programs:
• makelist makes a list upon which the other programs operate
```    x = new;
L0;
y = new;
y.+f;
y.f = x;
x = y;
##L0
```
```    z = x;
L0;
- z/g {;
z.+g;
};
+ z/f {;
z = z.f;
}{;
z = x;
};
##L0
```
```    y = x;
L0;
+ y/g {;
y.-g;
};
+ y/f {;
y = y.f;
}{;
y = x;
};
##L0
```
We start our parallel simulation with the following command:
parsim -P PGLEc -B MPP -l makelist -l addfield -l delfield
It starts a simulator for each programs with PGLEc as instruction set and MPP for basic instructions, the parsim controller for starting more simulators, and a graphical view of the core of MPP.

After this, the following operations must be performed:

run makelist
stop makelist
run delfield

Now play around with the stop and run buttons in the simulators for addfield and delfield.

## Interacting programs with the use of semaphores

In the above demonstration, the programs addfield and delfield use a single instruction for adding and deleting fields. Because of this, these operations do not interfere with each other. If we apply operations that consists of more than one instructions, we should take care of preventing interference. In this demonstration we use semaphores to do this.

The basic instruction

``````
semaphorex.+lock
```
```
adds a field `lock` to the focus `semaphorex` and returns the value `true`. If the field `lock` already exists, the value `false` is returned. So we can use this instruction as a semaphore.

We use three programs:

• initlists initializes list x and y and their semaphores
```    semaphorex = new;
x = new;
semaphorey = new;
y = new
```
• addlists tries to add elements to the lists x and y
```    L0;
+ semaphorex.+lock {;
hx = new;
hx.+f;
hx.f = x;
x = hx;
semaphorex.-lock;
};
+ semaphorey.+lock {;
hy = new;
hy.+f;
hy.f = y;
y = hy;
semaphorey.-lock;
};
##L0;
```
• dellists tries to delete elements from the lists x and y
```    L0;
+ semaphorex.+lock {;
+ x/f {;
hx = x;
x = x.f;
hx.-f;
rma hx;
};
semaphorex.-lock;
};
+ semaphorey.+lock {;
+ y/f {;
hy = y;
y = y.f;
hy.-f;
rma hy;
};
semaphorey.-lock;
};
##L0;
```
We start our parallel simulation with the following command:
parsim -P PGLEc -B MPP -l initlists -l addlists -l dellists
The following operations must be performed:
run initlists