#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include "mpi.h"

#include "mpi_bnc.h"

double f(double a)
{
	return (4.0 / (1.0 + a*a));
}

int main(int argc,char *argv[])
{
	int n, myid, numprocs, i;
	double pi, start_x, end_x;
	double startwtime = 0.0, endwtime;
	int  namelen;
	char processor_name[MPI_MAX_PROCESSOR_NAME];

	MPI_Init(&argc,&argv);
	MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
	MPI_Comm_rank(MPI_COMM_WORLD,&myid);

	n=14 * 16384;

	if(myid == 0) startwtime = MPI_Wtime();
	start_x = 0.0; end_x = 1.0;
	_mpi_dtrapezoidal_fs(&pi, start_x, end_x, f, n, MPI_COMM_WORLD);
	if(myid == 0)
	{
		endwtime = MPI_Wtime() - startwtime;
		printf("BNC: _mpi_dtrapezoidal_fs = %e\n", pi);
		printf("Time: %f\n", endwtime);
	} 

	MPI_Finalize();

	return EXIT_SUCCESS;
}
