view OctConf2013/examples/Pi.m @ 8:50abddcc3409 default tip

Presentation delivered by cdf at OctConf 2013.
author Carlo de Falco <cdf@users.sourceforge.net>
date Mon, 22 Jul 2013 21:54:27 +0200
parents FEMTEC2013/examples/Pi.m@60233b0075a9
children
line wrap: on
line source

  T=clock; 
  MPI_ANY_SOURCE = -1;
  MPI_Init ();  
  MPI_COMM_WORLD = MPI_Comm_Load ("NEWORLD");           
  rnk   = MPI_Comm_rank (MPI_COMM_WORLD);
  siz   = MPI_Comm_size (MPI_COMM_WORLD);
  SLV = logical(rnk);                 
  MST = ~ SLV;                        
  width=1/N; lsum=0;
  i=rnk:siz:N-1;    
  x=(i+0.5)*width;  
  lsum=sum(4./(1+x.^2));
  TAG=7;                
  if SLV                
    MPI_Send (lsum, 0, TAG, MPI_COMM_WORLD);
  else                  
    Sum =lsum;          
    for slv=1:siz-1     
      lsum = MPI_Recv (MPI_ANY_SOURCE, TAG, MPI_COMM_WORLD);
      Sum += lsum;      
    endfor              
  endif
  MPI_Finalize ();