/* COMP 137 Spring 2020 - April 16 - In-class MPI Lab 2* filename: mpi_pi_darts.c** Purpose: Estimate the value of PI using the dartboard method.*Parallelized as MPI processes.** Today's exercise: This is currently a serial program.*Parallelize it with MPI.*/#include <stdio.h>#include <stdlib.h>#include <math.h>#include <time.h>#include <mpi.h>/* global values */long dart_count = 1000000000;/* forward reference */long throwDarts(long num_darts, double radius);/*--------------------------------------------------------------------*/int main(int argc, char* argv[]){int rank;// rank of this processint comm_size;// number of processesdouble PI;int source;long total_darts, total_hits;long my_darts, my_hits;double start , finish ;long comm_buff[2];double MPI_Wtime(void);/* ICE10: initialize MPI, determine number of processes and rank. */MPI_Init(&argc,&argv);////////////////////////////////////////////////////////////////////MPI_Comm_size(MPI_COMM_WORLD, &comm_size);MPI_Comm_rank(MPI_COMM_WORLD, &rank);printf ("MPI task %d has started...\n", rank);/* Set seed for random number generator equal to rank ID */srand(rank);///srand(time(0)); /* seed the random number generator*/ ////////////////////////////////////////////////////////////////////my_darts = dart_count / comm_size;my_hits = throwDarts(my_darts, 1.0);if(rank != 0){/* ICE10: If this is not process 0,* send my_darts and my_hits to process 0.*/// MPI_Send(&my_darts, 1, MPI_LONG, 0, 0, MPI_COMM_WORLD);