home *** CD-ROM | disk | FTP | other *** search
- /*
- ptp.c Parallel Test Program
- (C) 1993 Macquarie University
- Released without ANY warranty to the public domain.
- Written by Richard Larkin. rlarkin@zen.efs.mq.edu.au
-
- Demonstration of pseudo(?) parallel processing.
-
- Calculates a total using however many processes are requested
- on the command line.
-
- e.g
-
- ptp, ptp 0 Crash and dump core.
- ptp 1 Use a single process.
- Does not use mapped file.
- ptp 2 2 processes used. This may make use of
- 2 processors as well if the machine is parallel.
- ptp 128 Wish I had that many processors.
-
- To compile...
- gcc -o ptp ptp.c parallel.c -DSUN -lm
-
- Portability...
- Works on SUNOS based SUNs and MSDOS PCs, don't know about any others.
- */
-
- #include "parallel.h"
-
- #define ARRAYSIZE 80000
-
- void main(int argc, char *argv[])
- {
- long int i, Min, Max;
- float *t, s;
-
- ParallelProcessors(atol(argv[1]));
-
- t = ParallelTypeCalloc(float, ARRAYSIZE);
-
- ParallelSplit(ARRAYSIZE, &Min, &Max);
- puts("Processing");
- for (i = Min; i < Max; i++)
- {
- /* Nonsense calculation. */
- s = (float) i / 10000.0 + 1.0;
- t[i] = log(abs(log((double) s) * log((double) s * s) + 1.0)) *
- log(abs(log((double) s + 1.0) * log((double) s * s + 1.0) + 2.0));
- }
- ParallelRegroup();
-
- for (i = 0, s = 0.0; i < ARRAYSIZE; s+=t[i++]);
- printf("Total is %f\n", s);
-
- ParallelFree(t);
- }
-
-