#include #include #include #include "pvm3.h" #include "stopwatch.c" int short_comp (const void *, const void *); main() { int mytid; /* my task id */ int tids[32]; /* task ids */ int me, i, nproc, master, msgtype, part_num; long n; short *data; char hostbuf[255]; /* enroll in pvm */ mytid = pvm_mytid(); /* Receive data from master */ msgtype = 1; pvm_recv( -1, msgtype ); pvm_upkint(&part_num, 1, 1); pvm_upklong(&n, 1, 1); data = new short[n]; pvm_upkshort(data, n, 1); /* Do calculations with data */ stopwatch timer_calc; timer_calc.start(); qsort(data, n, sizeof(short), short_comp); timer_calc.stop(); /* Send result to master */ pvm_initsend( PvmDataDefault ); pvm_pkint(&mytid, 1, 1 ); gethostname(hostbuf, 255); pvm_pkstr(hostbuf); pvm_pkint(&part_num, 1, 1 ); double calc_elapsed = timer_calc.read(); pvm_pkdouble(&calc_elapsed, 1, 1 ); pvm_pklong(&n, 1, 1 ); pvm_pkshort(data, n, 1 ); master = pvm_parent(); pvm_send( master, 5 ); /* Program finished. Exit PVM before stopping */ pvm_exit(); } int short_comp (const void * a, const void * b) { return ( *(short*)a - *(short*)b ); }