static char rcsid[] = "$Id: trsg.c,v 1.6 2009/01/23 01:20:23 pvmsrc Exp $"; /* * PVM version 3.4: Parallel Virtual Machine System * University of Tennessee, Knoxville TN. * Oak Ridge National Laboratory, Oak Ridge TN. * Emory University, Atlanta GA. * Authors: J. J. Dongarra, G. E. Fagg, M. Fischer * G. A. Geist, J. A. Kohl, R. J. Manchek, P. Mucci, * P. M. Papadopoulos, S. L. Scott, and V. S. Sunderam * (C) 1997 All Rights Reserved * * NOTICE * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby granted * provided that the above copyright notice appear in all copies and * that both the copyright notice and this permission notice appear in * supporting documentation. * * Neither the Institutions (Emory University, Oak Ridge National * Laboratory, and University of Tennessee) nor the Authors make any * representations about the suitability of this software for any * purpose. This software is provided ``as is'' without express or * implied warranty. * * PVM version 3 was funded in part by the U.S. Department of Energy, * the National Science Foundation and the State of Tennessee. */ /* * Example of group Reduce, Scatter, and Gather functions - J.M. Donato * * This example calculates the sum of squares of the first N integers * in three different ways where * * N = (number of processors)*(number of elements per row) * * Note: This is obviously not an efficient way to compute the * sum of squares, but it is a cutesy example and test case. */ #include #ifdef HASSTDLIB #include #endif #include "pvm3.h" #define MAXNDATA 20 #define MAXNPROCS 16 #define DFLTNDATA 5 #define DFLTNPROCS 4 #define TASK_NAME "trsg" #ifdef WIN32 #undef min #undef max #endif #define min(x,y) ( ((x)<(y))? (x) : (y) ) #define max(x,y) ( ((x)>(y))? (x) : (y) ) extern void PvmMin(); extern void PvmMax(); extern void PvmSum(); extern void PvmProduct(); void MaxWithLoc(); main() { int myginst, i, j, gsize, count, nprocs, msgtag, datatype; int info_product, info_user; int tids[MAXNPROCS], myrow[MAXNDATA], matrix[MAXNDATA*MAXNPROCS]; float values[2]; int midpoint, bigN, Sum1=0, Sum2=0, SumSquares, rootginst; int PSum = 0, PartSums[MAXNPROCS], dupls[MAXNDATA]; char *gname = "group_rsg"; /* join the group */ myginst = pvm_joingroup(gname); pvm_setopt(PvmAutoErr, 1); /* I am the first group member, get input, start up copies of myself */ if ( myginst == 0 ) { if (pvm_parent() == PvmNoParent) { printf("\n *** Example use of PVM Reduce, Scatter, and Gather *** "); printf("\n Number of processors to use (1-%d)? : ", MAXNPROCS); scanf("%d", &nprocs); if (nprocs > MAXNPROCS) nprocs = MAXNPROCS; printf(" Number of elements per row to use (1-%d)? : ", MAXNDATA); scanf("%d", &count); if (count > MAXNDATA) count = MAXNDATA; printf(" INPUT values: nprocs = %d, count = %d \n", nprocs, count); } else { count = DFLTNDATA; nprocs = DFLTNPROCS; } tids[0] = pvm_mytid(); if (nprocs > 1) pvm_spawn(TASK_NAME, (char**)0, 0, "", nprocs-1, &tids[1]); /* wait until they have all started, then send input values */ while (gsize = pvm_gsize(gname) < nprocs) pvmsleep(1); pvm_initsend(PvmDataDefault); pvm_pkint(&nprocs, 1, 1); pvm_pkint(&count, 1, 1); pvm_bcast(gname, msgtag=17); } else { /* receive the input values */ pvm_recv(-1, msgtag=17); pvm_upkint(&nprocs, 1, 1); pvm_upkint(&count, 1, 1); } rootginst = 0; /* determine the group root */ /* init the matrix values on the root processor */ if (myginst == rootginst) for (j=0; j x[i]) { x[i] = y[i]; x[i+count] = y[i+count]; } else if (y[i] == x[i]) x[i+count] = min(x[i+count], y[i+count]); *info = PvmOk; return; } /* end MaxWithLoc() */