Commit 53ff0e6e authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading

9780596005702

0 → 120000
+1 −0
Changes for 9780596005702: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
9780596005702
 No newline at end of file

README.md

0 → 100644
+15 −0
Changes for README.md: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
## Example files for the title:  
  
# High Performance Linux Clusters with OSCAR, Rocks, OpenMosix, and MPI, by Joseph Sloan
  
[![High Performance Linux Clusters with OSCAR, Rocks, OpenMosix, and MPI, by Joseph Sloan](http://akamaicovers.oreilly.com/images/9780596005702/cat.gif)](https://www.safaribooksonline.com/library/view/title/0596005709//)
  
The following applies to example files from material published by O’Reilly Media, Inc. Content from other publishers may include different rules of usage. Please refer to any additional usage rights explained in the actual example files or refer to the publisher’s website.
  
O'Reilly books are here to help you get your job done. In general, you may use the code in O'Reilly books in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from our books does not require permission. Answering a question by citing our books and quoting example code does not require permission. On the other hand, selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Incorporating a significant amount of example code from our books into your product's documentation does require permission.
  
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN.
  
If you think your use of code examples falls outside fair use or the permission given here, feel free to contact us at <permissions@oreilly.com>.
  
Please note that the examples are not production code and have not been carefully testing. They are provided "as-is" and come with no warranty of any kind.

c13p228.c

0 → 100644
+28 −0
Changes for c13p228.c: 28 added lines, 0 removed lines.
Original line number Diff line number Diff line
/* c13p228.c  
   Sample code from High Performance Linux Clusters,
   ISBN 0-596-00570-9
   (c) 2005 OReilly Media, Inc.
 */

#include "mpi.h"
#include <stdio.h>

int main( int argc, char * argv[] )
{
   int  processId;      /* rank of process */
   int  noProcesses;    /* number of processes */
   int  nameSize;       /* length of name */
   char computerName[MPI_MAX_PROCESSOR_NAME];

   MPI_Init(&argc, &argv);
   MPI_Comm_size(MPI_COMM_WORLD, &noProcesses);
   MPI_Comm_rank(MPI_COMM_WORLD, &processId);

   MPI_Get_processor_name(computerName, &nameSize);
   fprintf(stderr,"Hello from process %d on %s\n",
           processId, computerName);

   MPI_Finalize();

   return 0;
}

c13p234.c

0 → 100644
+33 −0
Changes for c13p234.c: 33 added lines, 0 removed lines.
Original line number Diff line number Diff line
/* c13p234.c  
   Sample code from High Performance Linux Clusters,
   ISBN 0-596-00570-9
   (c) 2005 OReilly Media, Inc.
 */

#include <stdio.h>

/* problem parameters */
#define f(x)            ((x) * (x))
#define numberRects     50
#define lowerLimit      2.0
#define upperLimit      5.0

int main ( int argc, char * argv[] )
{
   int         i;
   double      area, at, height, width;

   area = 0.0;
   width = (upperLimit - lowerLimit) / numberRects; 

   for (i = 0; i < numberRects; i++)
   {  at = lowerLimit + i * width + width / 2.0;
      height = f(at);
      area = area + width * height;
   }

   printf ("The area from %f to %f is: %f\n",
           lowerLimit, upperLimit, area );

   return 0;
}

c13p236.c

0 → 100644
+65 −0
Changes for c13p236.c: 65 added lines, 0 removed lines.
Original line number Diff line number Diff line
/* c13p236.c  
   Sample code from High Performance Linux Clusters,
   ISBN 0-596-00570-9
   (c) 2005 OReilly Media, Inc.
 */

#include "mpi.h"
#include <stdio.h>

/* problem parameters */
#define f(x)            ((x) * (x))
#define numberRects     50
#define lowerLimit      2.0
#define upperLimit      5.0

int main( int argc, char * argv[] )
{
   /* MPI variables */
   int dest, noProcesses, processId, src, tag;
   MPI_Status status;

   /* problem variables */
   int         i;
   double      area, at, height, lower, width, total, range;

   /* MPI setup */
   MPI_Init(&argc, &argv);
   MPI_Comm_size(MPI_COMM_WORLD, &noProcesses);
   MPI_Comm_rank(MPI_COMM_WORLD, &processId);

   /* adjust problem size for subproblem*/
   range = (upperLimit - lowerLimit) / noProcesses;
   width = range / numberRects;
   lower = lowerLimit + range * processId;

   /* calculate area for subproblem */
   area = 0.0;
   for (i = 0; i < numberRects; i++)
   {  at = lower + i * width + width / 2.0;
      height = f(at);
      area = area + width * height;
   }

   /* collect information and print results */
   tag = 0;
   if (processId == 0)         /* if rank is 0, collect results */
   {  total = area;
      for (src=1; src < noProcesses; src++)
      {  MPI_Recv(&area, 1, MPI_DOUBLE, src, tag,
                  MPI_COMM_WORLD, &status);
         total = total + area;
      }
      fprintf(stderr, "The area from %f to %f is: %f\n",
              lowerLimit, upperLimit, total );
   } 
   else                        /* all other processes only send */
   {  dest = 0; 
      MPI_Send(&area, 1, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD);
   };

   /* finish */
   MPI_Finalize();
   return 0;
}
Loading