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/
pvm_lib.o
to your makefile
.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");
printfs
with fprintfs
.pvm_spawn
function call. Firstly, the tid argument. This needs to be changed to an array, so that we can store the tid of every task spawned. Seeing as ntask is a command line argument, your array will need to be initialized dynamically. I suggest you use calloc to do this:turing.une.edu.au.Solutions> man calloc
pvm_spawn
should take a single element (the ith element) of the array as its tid argument. If a spawn fails, the error code will be returned in place of a tid. You should also pass the command line args to the child, so it can get the ntask value itself (use parse_args), otherwise you will have to send it to all children from the master. Compile this version and make sure it works correctly before you move on, my answer looks like:bourbaki.Solutions> ./hello_clean 3
from t80020: hello, world from b1
from tc0020: hello, world from b2
from t100020: hello, world from b3
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
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.
murderer.c
.Make your parent do the following:
ntask - 1
(the last tid).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.