

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: Introduction to Operating Systems; Subject: Computer Science; University: Baylor University; Term: Fall 2004;
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


CSI 4337 Programming Assignment 2 Due 10/06/ Fall 2004 PVM
Write a LINUX program to do binary fan- in to add up a list of numbers. For trial purposes, we will use the numbers 1-128, however in a real application, these would be array indices to a shared array rather than the actual numbers.
It will be necessary to create two separate programs. The actual work will be done by the client process which will work as follows.
The second program, the master program, must spawn a single client process and send a single message of type 100 to that process. Insert a 3-element array of ints into the message. The first int will be the process ID of the master process. The second will be the number 1. The third will be the number 128. The master process will then receive a single message of type 200 from the spawned process. It will extract a single integer from that message and print it with the text “The result is %d\n.”
To use PVM, you need to include the following file in your programs.
/usr/share/pvm3/include/pvm3.h
CSI 4337 Programming Assignment 2 Due 10/06/ Fall 2004 PVM
When compiling you need to add the following argument to the command line of the cc command.
cc MyProg.c /usr/share/pvm3/lib/LINUXI386/libpvm3.a -o MyProg
When running the program you need to start the PVM daemon. To do this, type the pvm command. When you get the pvm> prompt, type “quit” and press return. When you are done using the pvm daemon, type the pvm command again, but this type “halt” instead of “quit.”
The pvm function calls are used to interact with the pvm daemon. They will fail if the pvm daemon is not running. Here are the function calls you need. (The full description is available using the LINUX man command.)
int MyTid = pvm_mytid( ); // returns current process’s ID pvm_recv(-1,100); // receive a message of type 100 from anybody int MyArray[3]; pvm_upkint(MyArray,3,1); // extract an array of 3 integers from the most recently // received message pvm_initsend(PvmDataDefault); // do this to start creating a message pvm_pkint(MyArray,3,1); // insert an array of three elements into the current // message you are creating int OneValue; pvm_upkint(&OneValue,1,1); // extract a single integer from the most recently // message pvm_pkint(&OneValue,1,1); // insert a single integer into the message you are // creating int ParentID; pvm_send(ParentID,200); // send a message of type 200 to the process ID contained // in the variable ParentID. int ChildID; pvm_recv(ChildID,200); // receive a message of type 200 from the specific process // ID contained in the variable ChildID. int ChildIDs[2]; pvm_spawn("Client",NULL,PvmTaskDefault,"",2,ChildIDs); // spawn two new processes. The name of the program is “Client” the 2 indicates // the number of processes to start. The “ChildIDs” array must be an array of int // with one entry for each process spawned. The rest of the stuff is required // constants. pvm_exit( ); // Terminate this process from the pvm system.
To make this work, create the following directory in your home directory:
pvm3/bin/LINUXI
Place all your code in this directory.