/*--------------------------------------------------------------------------- / File: setup.c /---------------------------------------------------------------------------- / / This is a setup program for the 3-D matrix transposition problem / using pvm. / / The size of the 3-D matrix is taken as an argument, along with / the number of processors to use. / / This setup program spawns worker programs and / in the transposition. / /---------------------------------------------------------------------------- */ /* Contact: Karin A. Remington, karin@cam.nist.gov */ /* / Note: full path to pvm3.h is given in INCL compilation flag in makefile: */ #include "pvm3.h" #include #include #include int xpvm_connect(); main(argc, argv) int argc; char *argv[]; { int *tids; int i, j, k, slices, ntids, mytag; int size, sizesq, slicestart, index, slowproc; int type; int nodeid, parentid, rc; int nprocs, nworkers, narchs; struct hostinfo *hosts; char *my_hostname; double *f; double starttime, comtime, nodetime, maxtime, realtime(); /* / Enroll the manager program in PVM and return an id for this process... / and call pvmfconfig to return the # of nodes available (nprocs)... */ nodeid = pvm_mytid(); parentid = pvm_parent(); /* / Get hostname: */ my_hostname = (char *)malloc(8); gethostname(my_hostname,7); /* / If there is no parent for this process, take the role of manager / and start the other processes, sending each one an integer / which 'slice' of the matrix it is to handle. */ if ( parentid == PvmNoParent) { if (argc < 2) { printf("Usage: %s size num-procs \n", argv[0]); exit(1); } size = atoi(argv[1]); ntids = atoi(argv[2]); slices = size/ntids; if ( slices * ntids != size ) { printf("Error: number of processes (%d) must divide size (%d).\n", ntids, size); exit(1); } /* / Allocate space for the array of task ids, and put / this manager tasks id in first slot: */ tids = (int *) malloc(ntids*sizeof(int)); tids[0] = nodeid; /* / Spawn ntids - 1 copies. Their task ids will be placed in the / tids array for later use in message passing. */ xpvm_connect(); rc = pvm_spawn("setup", (char**)0, PvmTaskTrace, "", ntids-1, &tids[1]); if (rc != ntids-1) { printf("Error in spawning; Return code is %i\n",rc); pvm_exit(); exit(1); } for (i=1;i maxtime ) { maxtime = nodetime; slowproc = i; } } printf("Maximum process time: %4.2f (from process %d)\n", maxtime,slowproc); } else { pvm_initsend(PvmDataDefault); pvm_pkdouble(&comtime,1,1); pvm_send(parentid, 200); } /* / Call pvmfexit to terminate the PVM program gracefully... */ pvm_exit(); }