/* /---------------------------------------------------------------------------- / File: mplmanager.c /---------------------------------------------------------------------------- / / This is a trivial "hello world" program for illustrating the / use of the SP2 / / This manager program spawns copies of the program 'worker'. / /---------------------------------------------------------------------------- */ /* Contact: Karin A. Remington, karin@cam.nist.gov */ #include #include #include main(argc, argv) int argc; char *argv[]; { int i; int noderesult; int type; int msgid; int nprocs, nworkers; int nodeid; int nbuf[4], dontcare, allgrp; char *my_hostname; FILE *out_file; /* / Call mp_environ to return the # of nodes available (nprocs)... / and this node's id: */ mpc_environ(&nprocs, &nodeid); /* / Get manager hostname: */ my_hostname = (char *)malloc(8); gethostname(my_hostname,7); /* / Number of workers must be fixed in the case of MPL. / You can vary the number of processors with the environment / variable MP_PROCS */ nworkers = nprocs-1; /* / Learn value of allgrp and dontcare, for use with broadcast. */ mpc_task_query(nbuf, 4, 3); dontcare = nbuf[0]; allgrp = nbuf[3]; /* / Open the file for output */ out_file = fopen("mplmanager.results","w"); printf("----- MPL Program mplmanager ----\n"); fprintf(out_file,"----- MPL Program mplmanager ----\n"); /* / Broadcast the manager hostname to all processors... */ mpc_bcast(my_hostname, 7, nodeid, allgrp); /* / Send each processor an integer value to print out, modify and return. */ for (i=1;i<=nworkers;i++){ mpc_bsend(&i, 4, i, 100, msgid); }; /* / Now, the manager receives and prints the results of the workers. */ type = 200; for (i=1;i<=nworkers;i++){ mpc_brecv(&noderesult, 4, &i, &type, &msgid); printf("Result from task %d: %d\n",i,noderesult); fprintf(out_file,"Result from task %d: %d\n",i,noderesult); }; /* / Close the output file: */ fclose(out_file); }