1 / 15

Manifold Lab 2

Manifold Lab 2. Introduction Basic Concepts First Examples. Summary. Introduction Basic concepts Hello World Example Constructing manifold applications Fibonacci Series Example. Introduction. Coordination models fall into two categories:

kalil
Download Presentation

Manifold Lab 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ManifoldLab 2 Introduction Basic Concepts First Examples

  2. Summary • Introduction • Basic concepts • Hello World Example • Constructing manifold applications • Fibonacci Series Example

  3. Introduction • 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 manager (coordinator) is responsible for setting up and taking care of the communication needs of the group of worker processes it controls. • 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 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.

  4. Basic 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 worker’s 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.

  5. Basic 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 -> 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 e.g. 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.

  6. Infrastructure of a manifold process

  7. Hello World Example //hello.m manifold Main { begin: "Hello World!\n" -> stdout. } • 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 above 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.

  8. Hello 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!”-> 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” and an output port named “output”.

  9. Constructing 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 C (.ato.c) files which contain the code implementing the atomics (worker processes). • One or more interface (ato.h) files where we define the headers of the atomics that will be used by the coordinators. • 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

  10. Fibonacci Series Example

  11. Fibonacci Series Example (.m file) // 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).

  12. Fibonacci Series Example (.m file) begin:(v0->sigma.x, v1->sigma.y,v1->v0, sigma->v1,sigma->print). overflow.sigma:halt. } • The code we produce for this example produces the Fibonacci series which can be defined as the recurence of nν+1=nν-1+n. In the above code this addition is done by the atomic process Sigma. • 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 .

  13. Fibonacci Series Example (.ato.c file) //fibo.ato.c #include “/opt/Manifold/include/AP_interface.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);

  14. Fibonacci Series Example (.ato.c file) i3 = i1 + i2; /* calculate the sum */ if (i3 > 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 The above atomic produces sum repeatedly until it reaches the value MAXINT. Then it raises event too_big which preempts to state overflow in the manifold coordinator.

  15. Fibonacci 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_interface.h" extern void Sum(AP_Event too_big);

More Related