-
Book Overview & Buying
-
Table Of Contents
Raspberry Pi Super Cluster
By :
We have seen that we can calculate П with Hadoop. We can now try a similar application in C. The program we will now write will generate results similar to what we saw with the example program included with MPICH and will also use a MapReduce-style approach.
Create a new file at the following location to store your code in:
~/mpich3/code/monte_carlo_pi.c
Open this file and add the following code:
#include "mpi.h" #include <stdio.h> #include <stdlib.h> #include <time.h> double insidecircle(int throws); #define GAMES 20 #define THROWS 100
The previous block of code includes the necessary header files and defines a function and two constants. The function
insidercircle() will be responsible for calculating П.
The first constant is the number of
GAMES, that is, attempts at calculating П. The second defines the number of THROWS in each game. Now add the following code to the end of the file:
int main (int argc, char *argv[]) {
double jobaverage, calcpi...
Change the font size
Change margin width
Change background colour