home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume41 / parallel / part01 / ptp.c < prev   
Encoding:
C/C++ Source or Header  |  1993-12-19  |  1.4 KB  |  58 lines

  1. /*
  2.     ptp.c Parallel Test Program 
  3.     (C) 1993 Macquarie University
  4.     Released without ANY warranty to the public domain.
  5.     Written by Richard Larkin. rlarkin@zen.efs.mq.edu.au
  6.  
  7.     Demonstration of pseudo(?) parallel processing.
  8.  
  9.     Calculates a total using however many processes are requested
  10.     on the command line.
  11.  
  12.     e.g
  13.  
  14.     ptp, ptp 0    Crash and dump core.
  15.     ptp 1        Use a single process.
  16.             Does not use mapped file.
  17.     ptp 2        2 processes used. This may make use of
  18.             2 processors as well if the machine is parallel.
  19.     ptp 128        Wish I had that many processors.
  20.  
  21.     To compile...
  22.             gcc -o ptp ptp.c parallel.c -DSUN -lm
  23.  
  24.     Portability...
  25.     Works on SUNOS based SUNs and MSDOS PCs, don't know about any others.
  26. */
  27.  
  28. #include "parallel.h"
  29.  
  30. #define ARRAYSIZE     80000
  31.  
  32. void main(int argc, char *argv[])
  33. {
  34.   long int i, Min, Max;
  35.   float *t, s;
  36.  
  37.   ParallelProcessors(atol(argv[1]));            
  38.  
  39.   t = ParallelTypeCalloc(float, ARRAYSIZE);    
  40.  
  41.   ParallelSplit(ARRAYSIZE, &Min, &Max);    
  42.   puts("Processing");
  43.   for (i = Min; i < Max; i++)
  44.   {
  45.     /* Nonsense calculation.                                               */
  46.     s = (float) i / 10000.0 + 1.0;
  47.     t[i] = log(abs(log((double) s) * log((double) s * s) + 1.0)) * 
  48.            log(abs(log((double) s + 1.0) * log((double) s * s + 1.0) + 2.0));
  49.   }
  50.   ParallelRegroup();
  51.  
  52.   for (i = 0, s = 0.0; i < ARRAYSIZE; s+=t[i++]);
  53.   printf("Total is %f\n", s);
  54.  
  55.   ParallelFree(t);
  56. }
  57.  
  58.