/usr/lib/R/site-library/Rmpi/cslavePI.c is in r-cran-rmpi 0.6-6-4build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #include <mpi.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv){
int i, *univ_size, univ_flag, *n;
int rank, size;
double mypi, pi, h, sum, x;
MPI_Comm slavecomm, all_processes;
/*Initialize MPI*/
MPI_Init(&argc, &argv);
MPI_Comm_get_parent(&slavecomm);
MPI_Intercomm_merge(slavecomm, 1, &all_processes);
/*How many processes are there?*/
MPI_Comm_size(all_processes, &size);
/*Which one am I?*/
MPI_Comm_rank(all_processes, &rank);
MPI_Bcast(n,1,MPI_INT,0, all_processes);
/*Compute portion of pi on each node */
h = 1.0 / (double) (*n);
sum = 0.0;
for (i = rank ; i <= *n; i += size-1) {
x = h * ((double)i - 0.5);
sum += (4.0 / (1.0 + x*x));
}
mypi = h * sum;
/*Send all computed portion of pi to rank 0 and sum together */
MPI_Reduce(&mypi, &pi,1, MPI_DOUBLE, MPI_SUM,0, all_processes);
/*All done*/
MPI_Comm_free(&all_processes);
MPI_Finalize();
exit(0);
}
|