Index: Pi/C/MPI/Pi_MPI_LONG
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: Pi/C/MPI/Pi_MPI_LONG
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:mime-type
   + application/octet-stream

Index: Pi/C/MPI/Makefile
===================================================================
--- Pi/C/MPI/Makefile	(revision 0)
+++ Pi/C/MPI/Makefile	(revision 9)
@@ -0,0 +1,30 @@
+EXECUTABLE=Pi_MPI_LONG Pi_MPI_INTEGER
+
+SOURCE=Pi_MPI.c
+
+CC=mpicc.openmpi
+CFLAGS=-Wall -O3 -std=c99
+LIBRARY=-lm
+
+all: $(EXECUTABLE)
+
+Pi_MPI_LONG: $(SOURCE)
+
+	$(CC) $(CFLAGS) $(DIRECTIVES) -DLONG -o $@ $< $(LIBRARY)
+
+Pi_MPI_INTEGER: $(SOURCE)
+
+	$(CC) $(CFLAGS) $(DIRECTIVES) -DINTEGER -o $@ $< $(LIBRARY)
+
+.PHONY: clean check mrproper
+
+mrproper: 
+	rm -rf $(EXECUTABLE)
+	find . -name "*~" -exec rm {} \;
+
+clean:
+	find . -name "*~" -exec rm {} \;
+
+check: $(EXECUTABLE)
+
+	$(SOURCE:.c=)_SP_$(EXECUTABLE) 2 1
Index: Pi/C/MPI/Pi_MPI.c
===================================================================
--- Pi/C/MPI/Pi_MPI.c	(revision 0)
+++ Pi/C/MPI/Pi_MPI.c	(revision 9)
@@ -0,0 +1,119 @@
+//
+// Estimation of Pi using Monte Carlo exploration process
+// gcc -std=c99 -O3 -o Pi Pi.c -lm 
+//
+
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <mpi.h>
+
+// Marsaglia RNG very simple implementation
+#define znew  ((z=36969*(z&65535)+(z>>16))<<16)
+#define wnew  ((w=18000*(w&65535)+(w>>16))&65535)
+#define MWC   (znew+wnew)
+#define SHR3  (jsr=(jsr=(jsr=jsr^(jsr<<17))^(jsr>>13))^(jsr<<5))
+#define CONG  (jcong=69069*jcong+1234567)
+#define KISS  ((MWC^CONG)+SHR3)
+
+#define MWCfp MWC * 2.328306435454494e-10f
+#define KISSfp KISS * 2.328306435454494e-10f
+
+#define ITERATIONS 1000000000
+
+#ifdef LONG
+#define LENGTH unsigned long
+#else
+#define LENGTH unsigned int
+#endif
+
+LENGTH MainLoopGlobal(LENGTH iterations,unsigned int seed_w,unsigned int seed_z)
+{
+   unsigned int z=seed_z;
+   unsigned int w=seed_w;
+
+   unsigned  long total=0;
+
+   for (LENGTH i=0;i<iterations;i++) {
+
+      float x=MWCfp ;
+      float y=MWCfp ;
+
+      // Matching test
+      int inside=((x*x+y*y) < 1.0f) ? 1:0;
+      total+=inside;
+   }
+
+   return(total);
+
+}
+
+int main(int argc, char *argv[]) {
+
+  unsigned int seed_w=10,seed_z=10;
+  LENGTH iterations=ITERATIONS,inside[1024],insides,part_inside,part_iterations;
+  int numtasks,rank,rc,tag=1,i;
+  float pi;
+
+  MPI_Status Stat;
+
+  rc = MPI_Init(&argc,&argv);
+  if (rc != MPI_SUCCESS) {
+    printf ("Error starting MPI program. Terminating.\n");
+    MPI_Abort(MPI_COMM_WORLD, rc);
+  }
+
+  MPI_Comm_size(MPI_COMM_WORLD,&numtasks);
+  MPI_Comm_rank(MPI_COMM_WORLD,&rank);
+
+  if (rank==0) {
+
+    if (argc > 1) {
+      iterations=(LENGTH)atol(argv[1]);
+    }
+    else {
+      printf("\n\tPi : Estimate Pi with Monte Carlo exploration\n\n");
+      printf("\t\t#1 : number of iterations (default 1 billion)\n\n");
+    }
+
+    part_iterations=iterations/numtasks;
+    // Split part of code
+    for (i=1;i<numtasks;i++) {
+      rc = MPI_Send(&part_iterations, 1, MPI_UNSIGNED_LONG, i, tag, 
+                    MPI_COMM_WORLD);
+    }
+    
+    insides=MainLoopGlobal(part_iterations,seed_w,seed_z);
+    
+    // Join part of code
+    for (i=1;i<numtasks;i++) {
+      rc = MPI_Recv(&inside[i], 1, MPI_UNSIGNED_LONG, i, tag, 
+                    MPI_COMM_WORLD, &Stat);
+      printf("\tReceive %lu inside from %i\n",(unsigned long)inside[i],i);
+      insides+=inside[i];
+    }
+    
+    pi=4.*(float)insides/(float)((iterations/numtasks)*numtasks);
+    
+    printf("\tPi=%f with error %f and %lu iterations\n\n",pi,
+           fabs(pi-4*atan(1))/pi,(unsigned long)iterations);
+  }
+  else
+    {
+      // Receive information from master
+      rc = MPI_Recv(&part_iterations, 1, MPI_UNSIGNED_LONG, 0, tag, 
+                    MPI_COMM_WORLD, &Stat);
+
+      printf("\tOn %i, receive from master %lu\n",
+             rank,(unsigned long)part_iterations);
+      
+      part_inside=MainLoopGlobal(part_iterations,seed_w,seed_z);
+      
+      printf("\tOn %i, find %lu inside\n",rank,(unsigned long)part_inside);
+
+      rc = MPI_Send(&part_inside, 1, MPI_UNSIGNED_LONG, 0, tag, MPI_COMM_WORLD);
+    }
+  
+  MPI_Finalize();
+
+}
Index: Pi/C/MPI/Pi_MPI_INTEGER
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: Pi/C/MPI/Pi_MPI_INTEGER
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:mime-type
   + application/octet-stream

