Newsgroups: comp.parallel.pvm
From: atk@mathcs.emory.edu (Alan Krantz)
Subject: Alpha version of PVM-RPC
Organization: Emory University, Dept of Math and CS
Date: 19 Aug 1996 16:22:42 GMT
Message-ID: <4va4ci$n7j@cssun.mathcs.emory.edu>

I've been working on a project I call PVM-RPC. Basically the objective of this
project is to extend PVM to allow for the use an RPC like syntax for defining
and invoking remote procedures. In addition to an RPC like syntax the project
implements fault tolerance and other features when using a remote procedure.
These features and syntax of PVM-RPC was presented at last years pvm user
group meeting. Appended to this message I have included a copy of a pvm program
and a PVM-RPC program for performing matrix multiplication. We are at the 
stage where we have an alpha version of this software ready.  The current 
version is only guaranteed to run under Sun Solaris version 5.5.  If you are
interested in using PVM-RPC please send me email at atk@mathcs.emory.edu.
---

-----------------PVM-RPC VERSION of matrix multiply------------------------

---pvm_rpc_client.c----

#include <pvm3.h>
#include "pvm_rpc.h"
#define A_ROW 2
#define A_COL 100
#define B_ROW A_COL
#define B_COL 3

double a[A_ROW][A_COL] = {
 {3,1,-1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5},
 {2,0, 3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5}
};
double b[B_COL][B_ROW] = { 
  {1,3,2,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5},
 {4,-1,5,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5},
 {6,9,1,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5}
};
double c[A_ROW][B_COL];
PVM_RPC_TAG tags[A_ROW][B_COL];

main() {
    int i,j;
    pvm_setopt( PvmRoute, PvmRouteDirect );
/*
 * Start A_ROW * B_COL vector dot products
 */
    for(i=0; i < A_ROW; i++) {
        for(j=0; j < B_COL; j++) {
            pvm_rpc_ainvoke(vdot,tags[i][j], a[i],A_COL,b[j],B_ROW,&c[i][j],1);
        }
    }
/*
 * Wait for the completion of A_ROW * B_COL vector dot products
 */
    for(i=0; i < A_ROW; i++) {
        for(j=0; j < B_COL; j++) {
            pvm_rpc_wait(tags[i][j]);
        }
    }
    for(i=0; i < A_ROW; i++) {
        for(j=0; j < B_COL; j++) {
            printf("%10.5lf ",c[i][j]);
        }
        printf("\n");
    }
}    

---pvm_rpc_server.rpc------

#include <pvm3.h>
#include "pvm_rpc.h"
#include <signal.h>

pvm_rpc_service(vdot,IN PVM_DOUBLE a,IN PVM_DOUBLE b,OUT PVM_DOUBLE c) {
    int i,j;
    for(j=0; j < 100000; j++) {
        c[0] = 0;
        for(i=0; i < a_size; i += 1) {
            c[0] += a[i] * b[i]; 
        }
    }
}

pvm_rpc_main
------------------------------PVM versions of the above code-----------------

---pvm_mult_master.c

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


#define A_ROW 2
#define A_COL 100
#define B_ROW A_COL
#define B_COL 3

double a[A_ROW][A_COL] = {
 {3,1,-1,
 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5
,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5
,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5},
 {2,0,3,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5
,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5
,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5}
};
double b[B_COL][B_ROW] = {
  {1,3,2
,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,5,5,5,5,5,5,5,5,5
,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5
,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5},
 {4,-1,5
,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,5,5,5,5,5,5,5,5,5
,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5
,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5},
 {6,9,1
,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5}
};

double c[A_ROW*B_COL];

#define MAX_PROC 10

main(argc,argv)
char **argv;
int argc;
{
    int oldval,tids[MAX_PROC],cc,i,j,bufid,size,msgtag,sender;
    int N_PROC;

    oldval = pvm_setopt( PvmRoute, PvmRouteDirect );
    N_PROC = atoi(argv[1]);
    fprintf(stderr,"Using %d slaves\n",N_PROC);


    cc = pvm_spawn("/home/atk/work/pvm/pvm3/bin/SUN4SOL2/mult_slave", (char**)0,
0, "", N_PROC, tids);

    if (cc != N_PROC) {
        fprintf(stderr,"Error code %d in starting slave process.\r\n",cc);
        exit(0);
    }
    for(i=0; i < A_ROW; i++) {
        for(j=0; j < B_COL; j++) {
            pvm_initsend(PvmDataDefault);
            size = A_COL;
            pvm_pkint(&size,1,1);
            pvm_pkdouble(a[i],A_COL,1);
            pvm_pkdouble(b[j],B_ROW,1);
            pvm_send(tids[(i*B_COL+j)%N_PROC],i*B_COL+j);
        }
    }
    for(i=0; i < A_ROW; i++) {
        for(j=0; j < B_COL; j++) {
            bufid=pvm_recv( -1, -1 );
            pvm_bufinfo(bufid,&size,&msgtag,&sender);
            pvm_upkdouble(&c[msgtag],1,1);
        }
    }
    for(i=0; i < A_ROW; i++) {
        for(j=0; j < B_COL; j++) {
            printf("%10.5lf ",c[i*B_COL+j]);
        }
        printf("\n");
    }
    size = 0;
    for(i=0; i < N_PROC; i++) {
        pvm_initsend(PvmDataDefault);
        pvm_pkint(&size,1,1);
        pvm_send(tids[i],1);
    }
    pvm_exit();
}

--- pvm_mult_slave.c ---

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

main() {
    int ptid,oldval,len,i,j,msgtag,bufid,mtid;
    double sum,*v1,*v2;
    oldval = pvm_setopt( PvmRoute, PvmRouteDirect );
    ptid = pvm_parent();
    mtid = pvm_mytid();


    pvm_initsend(PvmDataDefault);
    while(1) {
        bufid = pvm_recv(-1,-1);
        pvm_bufinfo(bufid, NULL, &msgtag, &ptid);
        pvm_upkint(&len,1,1);
        if(len == 0) {
            pvm_exit();
            exit(0);
        }
        v1 = (double *)malloc(sizeof(double)*len);
        v2 = (double *)malloc(sizeof(double)*len);
        pvm_upkdouble(v1,len,1);
        pvm_upkdouble(v2,len,1);
        for (j =0 ;j <100000 ;j ++) {
            sum = 0;
            for(i=0; i < len; i++) {
                sum += v1[i] * v2[i];
            }
        }
        pvm_initsend(PvmDataDefault);
        pvm_pkdouble(&sum,1,1);
        pvm_send(ptid,msgtag);
        free(v1);
        free(v2);
    }
    pvm_exit();
    exit(0);
}


----

--
Alan Krantz
atk@mathcs.emory.edu 		
Emory University, Atlanta, GA 

