Title: L61
1Manifold - Lab 2
- In this lecture we will discuss about
- Introduction to Manifold
- Basic Concepts
- First Examples
Giorgos Hadjipollas
2Summary
- Introduction
- Basic concepts
- Hello World Example
- Constructing manifold applications
- Fibonacci Series Example
- A detailed explanation of this lab examples can
be found here - More Manifold commands can be found in the
Manifold Reference Guide - A user guide for setting and testing Manifold can
be found here
3Introduction
- Coordination models fall into two categories
- Shared dataspace or data driven approach (Linda,
TupleSpaces) - Control or event driven approach (Manifold)
- In Manifold, processes communicate in a
point-to-point manner by means of well defined
interfaces (ports) - There exist two different types of processes
managers (or coordinators) and workers. - A worker gets some input through its input ports,
performs a computation and places the results in
its output ports. - It is unaware of who needs the results it
computes or from where it itself receives the
data to process. - A manager (coordinator) is responsible for
setting up and taking care of the communication
needs of the group of worker processes it
controls. - A coordinator process waits to observe an
occurrence of some specific event (usually raised
by a worker process it coordinates) that triggers
it to enter a certain state and perform some
actions. - These actions typically consist of setting up or
breaking off connections between ports of
workers.
4Basic concepts
- Processes
- A black box with well-defined ports of connection
through which it exchanges units of information
with the rest of the world. - Can be either a manager (coordinator) process or
a worker. - A manager process is responsible for setting up
and managing the computation performed by a group
of workers. - Note that worker processes can themselves be
managers of subgroups of other processes and that
more than one manager can coordinate a workers
activities as a member of different subgroups. - The bottom line in this hierarchy is atomic
processes, which may in fact be written in any
manifold-compliant programming language. - Ports
- Named openings in the boundary walls of a process
through which units of information are exchanged
using standard I/O type primitives analogous to
read and write. - Each port is used for the exchange of information
in only one direction either into (input port)
or out of (output port) a process. - We use the notation p.i to refer to the port i of
a process instance p.
5Basic concepts (2)
- Streams
- These are the means by which interconnections
between the ports of processes are realized. - A stream connects a (port of a) producer
(process) to a (port of a) consumer (process). - We write p.o -gt q.i to denote a stream connecting
the port o of a producer process p to the port i
of a consumer process q. - Events
- Independent of streams, there is also an event
mechanism for information exchange. - Events are broadcast by processes to their
environment in order to publish the occurrence of
an event - the completion of a computation,
- an error occurrence,
- the need for data.
- In principle, any process in the environment can
pick up a broadcast event in practice though,
usually only a subset of the potential receivers
is interested in an event occurrence. - We write e.p to refer to the event e raised by a
source process p.
6Infrastructure of a manifold process
7Hello World Example
- Every manifold program must include a Main
manifold. - It is analogous to Java or C main function
- A manifold consists of a number of states.
- When it is instantiated it enters the begin state
and executes the commands of the state body. - After the execution of a state body, it remains
at this state until it observes the occurrence of
some other event. - For every event that the manifold is interested
in, there is one state with the same name. - The receipt of an event triggers the manifold to
enter the corresponding state. - In the following example the Main manifold enters
the begin state and sends the string Hello
World!\n to the standard output. - The standard output is itself a process that
receives data in its input port and prints this
data to the screen.
//hello.m manifold Main begin "Hello
World!\n" -gt stdout.
8Hello World Example (2)
- An alternative way for writing the Hello World
example is - include "rdid.h
- manifold printunits import.
- auto process print is printunits.
- manifold Main()
-
- begin Hello World!-gt print.
-
- In the above program we use a predefined atomic
process called printunits. - The first command declares the print as an
instance of printunits. - The auto prefix is used to instantiate that
instance automatically upon manifold creation. - When the Main manifold is created it enters the
begin state and sends the string Hello World!
to the input port of print atomic process. - When we do not define any ports for the
processes, two ports are created by default - An input port named input
- An output port named output.
9Constructing of a manifold application
- A complete manifold application that contains
both manifold and atomic processes is set of - One or more .m files that contain the code of the
coordinator processes. - One of these files contains the main() manifold.
- One or more interface (ato.h) files where we
define the headers (interface) of the atomics
that will be used by the coordinators. - One or more C (.ato.c) files which contain the
code implementing the atomics (worker processes).
- We can create a .m file for each coordinator or
include all coordinators in one file. - The same can be applied to atomics i.e. we can
create a .ato.c file for each atomic or include
all atomics in one ato.c file
10Fibonacci Series Example
11Fibonacci Series Example (.m file)
The code of this example produces the Fibonacci
series which can be defined as the recurrence of
n?1n?-1n?. In the code below this addition is
done by the atomic process Sigma.
// fibo.m //pragma include "fibo.ato.h" manifold
printunits import. manifold variable(port in)
import. manifold Sum(event) port in x. port
in y. atomic internal.. manifold Main()
event overflow. auto process v0 is variable(0).
auto process v1 is variable(1). auto process
print is printunits. auto process sigma is
Sum(overflow). begin( v0-gtsigma.x,
v1-gtsigma.y,v1-gtv0, sigma-gtv1,sigma-gtprint).
overflow.sigmahalt.
include fibo.ato.h
We first declare the three types of the processes
we are about to use. The PrintUnits and variable
are imported from a library. Sum is an atomic
specially designed to perform the Fibonacci
calculation.
The main manifold consists of two states begin
which executes the required connections between
the already activated processes overflow.sigma
which terminates the program, when the overflow
event is received by the main process. This event
is expected to be raised by the sigma atomic
instance when the sum it produces exceeds a
certain maximum number
12Fibonacci Series Example (.ato.h file)
The atomic has to be declared as an external void
in the interface file fibo.ato.h so that it can
be exported to any manifold coordinator. //fibo.
ato.h include "/opt/Manifold/include/AP_interfac
e.h" extern void Sum(AP_Event too_big)
13Fibonacci Series Example (.ato.c file)
//fibo.ato.c include /opt/Manifold/include/AP_in
terface.h" include "fibo.ato.h " include
"adid.h"define MAXINT 1000void Sum(AP_Event
too_big) int i1, i2, i3 int x
AP_LocalPortId("x") / declare an index for
/ int y AP_LocalPortId ("y") / every
i/o port / int out AP_LocalPortId
("output") AP_Unit u1, u2, u3 // declare
units for passing values to the i/o ports
while (1) AP_PortRemoveUnit(x,
u1, NULL) / get data units from input /
AP_PortRemoveUnit(y, u2, NULL) / ports x and
y / AP_FetchInteger(u1, i1) /
and allocate them to / AP_DeallocateUnit(u1)
/ integer variables i1 i2 /
AP_FetchInteger(u2, i2) AP_DeallocateUnit(u2
) i3 i1 i2 / calculate the sum
/ if (i3 gt MAXINT) / if max. Fib.
Number reached / AP_Raise(too_big) /
raise event overflow / return u3
AP_FrameInteger(i3) AP_PortPlaceUnit(out, u3,
NULL) / put result in the /
AP_DeallocateUnit(u3) / output port /
//end while//end Sum