/* @TITLE "Message-passing Matrix multiply" */ /* * Message-passing matrix multiply example * MASTER * * David Kotz 1991 */ #include #include "p4.h" #include "dfk.h" #include "broadcast.h" #include "mpmatrix.h" char *progname; extern void do_one_row(); /* @SUBTITLE "main program: master" */ main(argc, argv) int argc; char **argv; { int nprocs; /* number of processes to use */ int node; /* our node number */ int N; /* the size of each square matrix */ boolean printmatrix; /* should we print the matrix? */ struct problem_s prob,*message; /* problem description */ int length; /* size of message */ p4_initenv(&argc, argv); /* Get arguments */ progname = argv[0]; if (argc < 2) { fprintf(stderr, "usage: %s [p4opts] N [print]\n", progname); exit(-1); } N = atoi(argv[1]); if (N < 1) { fprintf(stderr, "%s: N=%d; should be > 0. (N=atoi(%s))\n", progname, N, argv[1]); exit(-1); } printmatrix = (argc >= 3); /* GENERATE PROCESSES */ p4_create_procgroup(); nprocs = p4_num_total_slaves()+1; node = 0; /* I am master */ /* send problem size to all nodes */ prob.N = N; prob.printmatrix = printmatrix; length = sizeof(prob); message = &prob; broadcast(node, nprocs, &message, &length); if (nprocs != N) fprintf(stderr, "%s: Sorry, this program is too dumb to handle N<>P.\n", progname); else do_one_row(nprocs, node, printmatrix, N); /* we help out with the work */ p4_wait_for_end(); }