26 June 2011

Installing PVM on Ubuntu 10.10 64 bit


PVM is a software system that allows you to combine a number of computers which are connected over a network into a Parallel Virtual Machine. This machine can consist of computers with different architectures, running different flavors of the Unix/Linux operating systems, and can still be treated as if it were a single parallel machine.

The simpler way to install PVM is
1. Go to the synaptic package manager and install pvm, libpvm3, xpvm.
2. Or type in terminal $sudo apt-get install pvm

Check if the PVM libraries in /usr/lib/pvm3  or in /usr/local/lib/pvm3 and include files in /usr/include directory.

Configuring PVM to work on different machines -
1. Find out which computers are available. You can use any computer on which you have an account,    and on which PVM is installed.

2. Edit or create the file .rhosts in your home directory. This file must have an entry for every computer you want to use. The entry is in the form of the name of the computer and your login name on that machine:
 ucs.orst.edu  kowallih
dogby.physics.edu hans

If your login name is the same on all machines, then you can leave the field with the login name blank, but it doesn’t hurt to put it in.

3. Set the environment variables in the .bashrc file.
export PVM_ROOT="/usr/lib/pvm3"
export PVM_ARCH=`$PVM_ROOT/lib/pvmgetarch`
export XPVM_ROOT=/usr/bin/xpvm
export PVM_RSH=`which ssh`

4. Create directories for your executables:
    $mkdir $HOME/pvm3/bin/PVM ARCH
where PVM ARCH is the PVM code for the architecture. Although this step is not necessary for PVM to work, it will make your life much easier if you are going to use PVM on computers with different architectures. You can find the code for each computer’s via the PVM function pvmgetarch.

The PVM console
The PVM console is the interface between the parallel virtual machine and the user. You use it to start and stop processes, to display information about the state of the virtual machine, and most importantly, to start and stop PVM on local and remote machines.

Step 1: Starting PVM Log into one of the computers you want to include in
PVM and enter:
pvm>

Step 2: Adding hosts This is done from the PVM prompt:
pvm> add <hostname>
where hostname is the name of the computer you want to add. This will start PVM
on the specified hosts and, if successful, will produce a message such as:
1 successful
HOST DTID
banana 140000
You can continue to add additional hosts as desired.

Step 3: Checking your configuration You display the configuration of your
parallel virtual machine from the PVM prompt:
pvm> conf
This will give you information about the hosts configured, their PVM identification
number and their architecture.

Step 4: Deleting hosts Sometimes it is necessary to remove hosts from the virtual
machine to test or debug a program:
pvm> delete <hostname>

Step 5: Leaving the console If you are done with setting up your virtual machine,
and if you don’t need any of the other functions of the console, you close the
console but keep PVM running:
pvm> quit

Step 6: Stopping PVM To stop PVM after your parallel program has finished,
enter the PVM console, and then from the PVM prompt:
> pvm From Unix shell
pvm> halt From PVM prompt
This stops PVM on all the machines and kills all programs running under PVM.
This is the best and easiest way to stop PVM.

A simple hello.c code to check the library.

#include <stdio.h>
#include <pvm3.h>

int main()
{
  int mytid;

  mytid = pvm_mytid();
  printf("My TID is %d\n", mytid);
  pvm_exit();
  return 0;
}

Compiling the code - 
$gcc hello.c -o hello -lpvm3
A simple master program master.c

#include <stdio.h>
#include <stdlib.h>
#include <pvm3.h>

int main()
{
  int myTID;
  int x = 12;
  int children[10];
  int res;

  myTID = pvm_mytid();
  printf("Master: TID is %d\n", myTID);

  res = pvm_spawn("slave", NULL, PvmTaskDefault, "", 1, children);
  if (res<1) {
    printf("Master: pvm_spawn error\n");
    pvm_exit();
    exit(1);
  }

  pvm_initsend(PvmDataDefault);
  pvm_pkint(&x, 1, 1);

  pvm_send(children[0], 1);

  pvm_recv(-1, -1);
  pvm_upkint(&x, 1, 1);

  printf("Master has received x=%d\n", x);

  pvm_exit();

  return 0;
}

A simple client program slave.c

#include <stdio.h>
#include <pvm3.h>

int main()
{
  int myTID, masterTID;
  int x = 12;

  myTID = pvm_mytid();
  printf("Slave: TID is %d\n", myTID);

  pvm_recv(-1, -1);
  pvm_upkint(&x, 1, 1);
  printf("Slave has received x=%d\n", x);

  sleep(3);
  x = x + 5;

  pvm_initsend(PvmDataDefault);
  pvm_pkint(&x, 1, 1);

  pvm_send(pvm_parent(), 1);

  pvm_exit();

  return 0;
}

Compiling the above code - 
$gcc -o master master.c -lpvm3
$gcc -o slave slave.c -lpvm3
Now copy the slave binary to the standard pvm folder so that master may know where to get the binary to spawn it.





3 comments:

  1. followed your steps but when i go to enter pvm> so that i can start pvm my bash comes back with syntax error near unexpected token `newline'

    ReplyDelete
    Replies
    1. This means that there is some error in your bash script. You might have missed either semicolon somewhere or there is unexpected newline. Go through your .bashrc file properly to check for errors while exporting pvm path.

      Delete
  2. Hi all,
    I have set up PVM as described above and it runs just fine and all the libraries are in place. But I'm encountering problem whenever i try to add a host system in my network, pvm is trying to connect to the host with the same name as my username. I tried add the entry in the .rhosts file but that dosen't help solve the problem. Can anyone help me connect to a host system in my network with a different user name

    ReplyDelete