PVM Parallel Virtual Machine Course CS 683 Computer












![PVM – Example /* spawn the child tasks */ info = pvm_spawn(argv[0], (char**)0, Pvm. PVM – Example /* spawn the child tasks */ info = pvm_spawn(argv[0], (char**)0, Pvm.](https://slidetodoc.com/presentation_image_h/befc42e3bc662d122b1df2d8f36d936e/image-13.jpg)




- Slides: 17

PVM (Parallel Virtual Machine) Course CS 683 Computer Architecture Prof. Moreshwar R Bhujade By : Vishal Prajapati

Contents • • • Introduction Features of PVM – as a System Example (Fork & Join) Summary

Introduction • PVM is a software tool for parallel networking of computers. • Major Acceptance because of • Developements in MPP – Powerfull computers (Blue gene) • Widespread use of distributed systems. • Source code • netlib (http: //en. wikipedia. org/wiki/Netlib) The Key consept is PVM allows to see the collection of computers as a one gient high performance machine.

Introduction • PVM is a software tool for parallel networking of computers. • Major Acceptance because of • Developements in MPP – Powerfull computers (Blue gene) • Widespread use of distributed systems. • Source code • netlib (http: //en. wikipedia. org/wiki/Netlib) The Key consept is PVM allows to see the collection of computers as a one gient high performance machine.

PVM (Physical Vs Logical View) Source : ftp: //ftp. netlib. org

Featurs of PVM - 1 • Portable • Runs on nearly every Unix machine, plus many shared- and distributedmemory multipro-cessors. • Heterogeneous • Any types of machines can be combined in a single virtual machine • Scalable • Virtual machines can include hundreds of host computers, and run thousands of tasks. • Dynamic configuration • computers can be dynamically added and deleted from the parallel virtual machine by the application or manually. • Hooks for fault tolerance • Application can be noticed via messages of lost processes, processors or addition of new resources.

Featurs of PVM - 2 • Dynamic process groups • user-defined process grouping for functions like broadcast and barrier. Groups can overlap and change dynamically during an application. • Signals • PVM tasks can send signals to other tasks. • Multiple message buffers • Allows easier development of PVM math libraries, graphical interfaces, etc. • Tracing • Call-level tracing built into PVM library. • Can be customized • User can write manager tasks to implement custom scheduling policies.

PVM - System • Composed of Two parts • PVM daemon – pvmd 3 or pvmd – For accepting remote connection and connecting to remote machines • PVM library – libpvm 3. a – Contains user callable routines for message passing, spawning processes, coordinating tasks, and modifying the virtual machine.

PVM – Example (Fork & Join) /* /* my task id */ Fork Join Example int mytid; Demonstrates how to spawn processes and exchange messages /* my parents task id */ */ int myparent; /* children task id array */ /* defines and prototypes for the PVM library */ int child[MAXNCHILD]; #include <pvm 3. h> int i, mydata, buf, len, tag, tid; /* Maximum number of children this program will spawn */ /* find out my task id number */ #define MAXNCHILD 20 mytid = pvm_mytid(); /* Tag to use for the joing message */ #define JOINTAG 11 /* check for error */ if (mytid < 0) { int /* print out the error */ main(int argc, char* argv[]) pvm_perror(argv[0]); { /* exit the program */ return -1; /* number of tasks to spawn, use 3 as the default */ } int ntask = 3; /* find my parent's task id number */ /* return code from pvm calls */ myparent = pvm_parent(); int info;

PVM – Example (Fork & Join) /* exit if there is some error other than Pvm. No. Parent */ if ((myparent < 0) && (myparent != Pvm. No. Parent)) { pvm_perror(argv[0]); pvm_exit(); return -1; } /* if i don't have a parent then i am the parent */ if (myparent == Pvm. No. Parent) { /* find out how many tasks to spawn */ if (argc == 2) ntask = atoi(argv[1]); /* make sure ntask is legal */ if ((ntask < 1) || (ntask > MAXNCHILD)) { pvm_exit(); return 0; } for (i = 0; i < ntask; i++) { /* recv a message from any child process */ buf = pvm_recv(-1, JOINTAG); if (buf < 0) pvm_perror("calling recv"); info = pvm_bufinfo(buf, &len, &tag, &tid); if (info < 0) pvm_perror("calling pvm_bufinfo"); info = pvm_upkint(&mydata, 1, 1); if (info < 0) pvm_perror("calling pvm_upkint"); if (mydata != tid) printf("This should not happen!n"); printf("Length %d, Tag %d, Tid t%xn", len, tag, tid); } pvm_exit(); return 0; } /* spawn the child tasks */ info = pvm_spawn(argv[0], (char**)0, Pvm. Task. Default, (char*)0, ntask, child); /* print out the task ids */ for (i = 0; i < ntask; i++) if (child[i] < 0) /* print the error code in decimal*/ printf(" %d", child[i]); else /* print the task id in hex */ printf("t%xt", child[i]); putchar('n'); /* i'm a child */ info = pvm_initsend(Pvm. Data. Default); if (info < 0) { pvm_perror("calling pvm_initsend"); pvm_exit(); return -1; } info = pvm_pkint(&mytid, 1, 1); if (info < 0) { pvm_perror("calling pvm_pkint"); pvm_exit(); return -1; } info = pvm_send(myparent, JOINTAG); if (info < 0) { pvm_perror("calling pvm_send"); pvm_exit(); return -1; } pvm_exit(); return 0; /* make sure spawn succeeded */ if (info == 0) { pvm_exit(); return -1; } /* only expect responses from those spawned correctly */ ntask = info; }

PVM – Example • It Contains both parent and child code. /* find out my task id number */ mytid = pvm_mytid(); • This function must be called before any other call. This call must be positive number. pvm_perror(argv[0]); • This call tells what goes wrong with the last call. /* find my parent's task id number */ myparent = pvm_parent(); • Retuns the Parent ID or else will retrn Error code “Pvm. No. Parent” says that the process is spawned by user and not by any other process.

PVM – Example • Following code differenciate the parent of all childs. /* if i don't have a parent then i am the parent */ if (myparent == Pvm. No. Parent) { • So by this you can differenciate the code of top process and child code. /* spawn the child tasks */ info = pvm_spawn(argv[0], (char**)0, Pvm. Task. Default, (char*)0, ntask, child); • This is the code which spawns childs.
![PVM Example spawn the child tasks info pvmspawnargv0 char0 Pvm PVM – Example /* spawn the child tasks */ info = pvm_spawn(argv[0], (char**)0, Pvm.](https://slidetodoc.com/presentation_image_h/befc42e3bc662d122b1df2d8f36d936e/image-13.jpg)
PVM – Example /* spawn the child tasks */ info = pvm_spawn(argv[0], (char**)0, Pvm. Task. Default, (char*)0, ntask, child); • Perameters • First perameter gives the name of the program that the child should run. • Second perameter is the arguments that can be passed to child • Third perameter – this says that where the child should spawn. We can give specific architecture or host name where the child can spawn • Fourth perameter will have the values of the third perameter • Fifth perameter specifies the number of the childs to be spawned. • Last perameter is the array name which holds the child Id's. • This Function is returning the no of child successfully spawned which should be equal to the sent number n the 5 th perameter other wise something gone wrong.

PVM – Example • Following code is the waiting blocking call of parent. /* recv a message from any child process */ buf = pvm_recv(-1, JOINTAG); • So by this parent is waiting for all the childs to send the join message. • Parent gets the data from the child via the message and the following code gets the data from the buffer. info = pvm_bufinfo(buf, &len, &tag, &tid); • After getting the join messages from all the childs parent also exits pvm.

PVM – Example • Following code is run by child. info = pvm_initsend(Pvm. Data. Default); info = pvm_pkint(&mytid, 1, 1); info = pvm_send(myparent, JOINTAG); pvm_exit(); • First line - For message to be sent first we need to create the buffer to send the data. • Second line – We are adding the child's Id to the message. • Third line sending the join call to the parent with the message attached. • Fourth line calls off the child from pvm and distroy its memory references.

PVM – Example (Fork & Join) Output % forkjoin t 10001 c t 40149 tc 0037 Length 4, Tag 11, Tid t 40149 Length 4, Tag 11, Tid tc 0037 Length 4, Tag 11, Tid t 10001 c % forkjoin 4 t 10001 e t 10001 d t 4014 b tc 0038 Length 4, Tag 11, Tid t 4014 b Length 4, Tag 11, Tid tc 0038 Length 4, Tag 11, Tid t 10001 d Length 4, Tag 11, Tid t 10001 e

Summary PVM is a software system that enables a collection of heterogeneous computers to be used as a coherent and flexible concurrent computational resource, or a "Parallel Virtual Machine". Thank You