Week 8 - Practical Exercise

Aims

Tasks

Exercise 1

Firstly, make sure you have a working version of hello_combined_hosts from the last tutorial, use the solution if necessary. You will also need the pvm_lib.* files from the lecture 16 examples:

http://turing.une.edu.au/~comp309/markdown_lectures/lecture_16/examples/

Exercise 2

Now copy hello_combined_hosts.c to hello_clean.c, and adjust the makefile by adding a target for hello_clean, and make it link with pvm_lib.o. Now, make the following changes: * Add #include "pvm_lib.h" * For every PVM function call, make sure you use the wrapper function, pvm_error_check. If you are not sure how it works, take a look at lecture 16. Your error checking should be similar to:


mytid = pvm_error_check(pvm_mytid(), "pvm_mytid");

Exercise 3

turing.une.edu.au.Solutions> man calloc
bourbaki.Solutions> ./hello_clean 3
from t80020: hello, world from b1
from tc0020: hello, world from b2
from t100020: hello, world from b3

Exercise 4

Now copy this working version to neighbours.c, and make the necessary adjustments to your makefile. In this version the idea is to get some information from the slaves regarding their neighbours. Imagine the slaves are a ring, which the master is not a part of. Each slave must work out where it is in the ring, and which slaves it has on its left and right.

An example of this can be found in lecture 16. You will need to:

bourbaki.Solutions> ./neighbours-1 4
from t80004: me=524292 left=1310724, right=786436, i'm from b1
from tc0004: me=786436 left=524292, right=1048580, i'm from b2
from t100004: me=1048580 left=786436, right=1310724, i'm from b3
from t140004: me=1310724 left=1048580, right=524292, i'm from b4

Exercise 5

OK, now copy neighbours-1.c to neighbours-2.c. Now make the following changes to neighbours-2.c:

    me = pvm_joingroup(GROUP);
    pvm_barrier(GROUP,ntask);

Note the use of the barrier, we want all spawned children to join the group before we move on. Also, you should make sure the child leaves the group before any call to pvm_exit().

pvm_lvgroup(GROUP);
tids[me - 1]

Should be replaced using the pvm_gettid() function:

pvm_gettid(GROUP, me-1)

Make sure this compiles and runs. Don’t forget to link with the PVM group library i.e gpvm3 when compiling. Your output should be similar to that of the neighbours-1 program.

Exercise 6

Exercise 7

Make your parent do the following:

Exercise 8

Now, you do the following in the child:

size = pvm_gsize(GROUP);
k_tid = pvm_gettid(GROUP, i);

Then you can kill it:

pvm_kill(k_tid);

To see the effects of killing, you would need to try interacting with the killed children i.e. try sending or receiving from them.