/*--------------------------------------------------------------------------- / File: mplworker.c /---------------------------------------------------------------------------- / / This is the worker program corresponding to the manager program: / / mplmanager.f / / It receives an integer message from the manager, prints it, / modifies it by adding 100, and then sends the results back / to the manager. /---------------------------------------------------------------------------- */ /* Contact: Karin A. Remington, karin@cam.nist.gov */ #include #include #include main(argc, argv) int argc; char *argv[]; { int nbuf[4], dontcare, allgrp; int nprocs, nodeid; int type; int hostid; int msgid; int i; char *my_hostname; char *manager_name; /* / Call mp_environ to return this node's id: */ mpc_environ(&nprocs, &nodeid); /* / Learn value of allgrp and dontcare, for use with broadcast. */ mpc_task_query(nbuf, 4, 3); dontcare = nbuf[0]; allgrp = nbuf[3]; /* / Get worker hostname: */ my_hostname = (char *)malloc(8); gethostname(my_hostname,7); /* / Participate in broadcast to get manager's hostname... */ manager_name = (char *)malloc(8); mpc_bcast(manager_name, 7, 0, allgrp); /* / Receive the start-up value from the manager... */ hostid = 0; type = 100; mpc_brecv(&i, 4, &hostid, &type, &msgid); printf("Stdout from node %d (%s): Received i = %d from host %s\n", nodeid, my_hostname, i, manager_name); /* / Now, perform a trivial computation on the integer value: */ i = i + 100; /* / Send the computed information back to the manager: */ mpc_bsend(&i, 4, 0, 200, msgid); }