miércoles, 2 de julio de 2014

riemann sum in parallel

Riemann sum

In mathematics, a Riemann sum is an approximation of the area of a region, often the region underneath a curve. It is named after German mathematician Bernhard Riemann.
The sum is calculated by dividing the region up into shapes (rectangles or trapezoids) that together form a region that is similar to the region being measured, then calculating the area for each of these shapes, and finally adding all of these small areas together.


For this form of integration, parallelism is very easy, for us to lodge an independence in the sum.


 
the riemann code is:

Sum_riemann(int a, int b, int d){
   sum=0 ;
   p=(b-a)/d;
  while(a<b){
     h=f(a+p/2) ;
     sum=sum+h*p;
     a=a+p;
  }
  return sum;

it is the code of riemann, in this code f is a function to evaluate the integral, 'A' is a min value of the integral and 'B' is the max value. 'D' is the number of rectangles used to calculate the integral.


for parallelization we use the following property



them the code in parallel is.

parrallel_riemann(a,b,d){
   size ;//number of core
   mypro;//id of core
   int a1,b1,d1,p1,p,sum1
   if(mypro==0){
         d1=d/size;
         p=(b-a)/size;
         a1=a;

        p1=p;
        b1=a1+p;
        send(a,all_cores) ;
        send(p,all_cores);
        send(d1,all_cores);
   }
   else{
        reciv(a1,core0,);
        reciv(p,core0);
       a1=a1+p*mypro;
       b1=a1+p;
       reciv(d1,core0);
   }
    MPI_Barrier;
   sum1=riemann_summ(a1,b1,d1);
   if(mypro!=0) send(sum1,core0);
   else{
       for(i=1;i<size;i++){
       reciv(ayu,core[i]) ;
      sum1=sum1+ayu;
      }
       return sum1;
     }
}



No hay comentarios:

Publicar un comentario