/*--------------------------------------------------------------------------- / File: manager.c /---------------------------------------------------------------------------- / / This is a trivial "hello world" program for illustrating the / use of the SP2 / / One argument is used, to tell the number of processes to create. / / ** Warning: For PVMe, the argument must be less that the number / of available processors. / / This manager program spawns copies of the program 'worker'. / /---------------------------------------------------------------------------- */ /* 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 main(argc, argv) int argc; char *argv[]; { int *tid; int i; int noderesult; int type; int hostid, nodeid, msgid, rc; int nprocs, nworkers, narchs; struct hostinfo *hosts; FILE *out_file; char *my_hostname; nworkers = atoi(argv[1]); /* / Enroll the manager program in PVM and return an id for this process... / and call pvmfconfig to return the # of nodes available (nprocs)... */ hostid = pvm_mytid(); pvm_config(&nprocs, &narchs, &hosts); if ( nworkers > nprocs - 1 ) { printf("Warning: If running under PVMe, too many workers have been requested.\n"); } /* / Allocate space for the array of task ids: */ tid = (int *)malloc(nworkers*sizeof(int)); /* / Get manager hostname: */ my_hostname = (char *)malloc(8); gethostname(my_hostname,7); /* / Open the file for output */ out_file = fopen("manager.results","w"); printf("----- PVM Program manager ----\n"); fprintf(out_file,"----- PVM Program manager ----\n"); /* / Spawn nworkers worker programs. Their task ids will be placed in the / tid array for later use in message passing. */ rc = pvm_spawn("worker", (char**)0, PvmTaskDefault, "", nworkers, tid); if (rc != nworkers) { printf("Error in spawning; Return code is %i\n",rc); pvm_exit(); exit(1); } /* / multi-cast (broadcast) the manager hostname to all processors... */ pvm_initsend(0); pvm_pkstr(my_hostname); pvm_mcast(tid, nworkers, 100); /* / Send each processor an integer value to print out, modify and return. */ for (i=0;i