viernes, 11 de julio de 2014

Experimento Conectando dos compus en paralelo

Intentare conectar dos computadoras, en paralelo usando el protocolo MPI
las propiedades de las computadoras son

COMPU 2



Inciando servidor ssh en la compu 2


empesando el segundo paso, intenamos solamente comunicarnos, aprecio el error 1

me pedia permiso para ingresar como mi usuario, carlos@172.....
bien pensamos que es porque en la compu primcipanl nunca inicie ssh

BIen no podiamos porque no estaba instalado el ssh server solo el conector:P


parece que si pudimos contactarnos desde la otro lado



bien parece que no es el error, nos pide entrar como carlos@172.20.16.12 es decir esta intentando entrar como carlos a la otra compu :(

que pasa si nos metemos como superusuario ?
ocurre lo mismo :( nos pide autentificarnos a la otra red, le colocamos la clave y aun asi nos deniega el aceso

bueno parece que tenemos que tener el mismo nombre de acceso para tener acceso :(

ingresamos cambiamos la clave de root de la segunda pagina con un 1234 :P nada mas
y ahor apodemos correr nuestro programa otra ves aver que nos dice

bien el cambio solo se iso en root nada mas :P

el link de la pagina es
http://doutdex.wordpress.com/2008/05/02/como-cambiar-password-clave-usuario-root-ubuntu/

bien ahora nos aparece otro error






Quisas probemos si esque la otra compu la numero 2, tiene instalado MPI
no lo tiene :(
es posible que eso sea el error :(

bien parece que necesitamos ambos computadoras con MPI utilizaremos la instalación básica de MPI manual, utilizaremos el otro post

Una ves terminada la instalación corremos el programa otra ves para ver si ahora ejecuta.

Bien no funciona sigue existiendo el error en el archivo Hidra.

Bien el error ahora es un poco mas complicado, el archivo Hidra que nos muestra el error se encuentra en la uvicación /usr/bin en la computadora 1 y /home/fablab/Carlos/instalacion/bin en la computadora 2, esto es lo que nos genera el error
pues generalemente se supone deveria estar en el mismo lugar.

biene vemos que no hay forma tenemos que reparar lo que emos echo desisntalaremos todo y generaremos denuevo la instalación de esa forma estaran hydra en el mismo lugar asi podra correr creemos el programa.

Ni modo eliminaremos la carpeta que hemos creado en instalación y generaremos otra instalacione sta ves en /usr nada mas, eso devera de generarnos algo con suerte.

Cambio el error ahora nos aparece el sigiente lista de errores.


Para toda la comunicación se usa doble llaves, pues es demaciado engorroso escribir una y otra ves la clave de un servidor ssh, asi pues, en lugar de escribir la clave, generamos dos llaves en el protocolo ssh, una llave publica y otra privada, ese es el siguiente paso, no creo k ese sea el problema pero lo intentaremos.



ayudas
http://blog.desdelinux.net/ssh-sin-password-solo-3-pasos/
http://doutdex.wordpress.com/2008/05/02/como-cambiar-password-clave-usuario-root-ubuntu/


miércoles, 2 de julio de 2014

Simpson's rule in parallel

Simpson's rule

 In numerical analysis, Simpson's rule is a method for numerical integration, the numerical approximation of definite integrals.

 

More info

 

for this method of integral we use this solution strategy.



 
we can see the original form of the problem and how the solution will be planted.

in the formula above, each "Y" is a function evaluated at each 'X'. 'H' is the distance between each 'X'.

the simpson code is:

   simpson(a,b,n) {
        n=n*2;
        h=(b-a)/n;
       sum=f(a)+f(b);
       for(i=1;i<=(n-1));i+=2){
                sum=sum+4*f(a+h*i);
       }
       for(i=2;i<=(n-2);i+=2){
               sum=sum+2*f(a+h*i) ;
       }
       sum=sum*h;
       sum=sum/3;
      return sum;
   }

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. 'N' is the number of interval used to calculate the integral.


We can combine both 'FOR' into one.

for(i=1;i<(n-1);i++){
     if(i%2==0) sum=sum+2*f(a+h*i);
     else             sum=sum+4*f(a+h*i);
}
now parallelize this 'FOR'.

we can divide the 'FOR' between 'P' processors. 


for(i=1;i<(n-1);i++){
    if((i%size)==mypro){
              if(i%2==0) sum=sum+2*f(a+h*i);
              else             sum=sum+4*f(a+h*i);
    }
}

ready, the code would end.


simpson(a,b,n) {
       size;//number of cores,
       mypro;//id of core;

        n=n*2;
        h=(b-a)/n;
        if(mypro==0)    sum=f(a)+f(b);
        else   sum=0;
    
     for(i=1;i<(n-1);i++){
           if((i%size)==mypro){
                  if(i%2==0) sum=sum+2*f(a+h*i);
                  else             sum=sum+4*f(a+h*i);
           }
     }
        if(mypro!=0) send(sum,core0);
       else{
             for(i=1;i<size;i++) {
                     recv(ayu,core[i]) ;
                     sum=sum+ayu;
              }
       }
        if(mypro==0){
               sum=sum*h;
               sum=sum/3;
                return sum;
         } 
}
 

 

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;
     }
}



sábado, 21 de junio de 2014

MPI commands that will be used in this blog


  In this blog I will explain the basic commands mpi will use in this blog and video tutorials.


 MPI_Init( &argc, &argv );

this command we will be used in the initiation of our code.
this code is used to start parallel communication between processors.

MPI_Finalize();

this command will be used in the completion of our code
Terminates MPI execution environment



   MPI_Comm_size( MPI_COMM_WORLD, &nprocs );
 where nprocs is a integer.
This command saves the number of processors in nprocs.



   MPI_Comm_rank( MPI_COMM_WORLD, &myproc );
where myproc is a integer.
this command gives us a number to identify each processor, and will be different for each processor.



   MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
where buf is initial address of send buffer
where count is number of elements in send buffer (nonnegative integer)
where datatype is datatype of each send buffer element.
where  dest is rank of destination, this is obtained by the command MPI_Comm_rank
where tag is message tag (integer), This is used to distinguish messages sent.
where comm is communicator, for these examples we used MPI_COMM_WORLD
This command allows us to communicate between processors.


 MPI_Recv(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status)
where buf is initial address of receive buffer (choice)   OUTPUT
where count is maximum number of elements in receive buffer (nonnegative integer)
where datatype is datatype of each receive buffer element.
where source is rank of source this is obtained by the command MPI_Comm_rank
where tag is message tag, This is used to distinguish messages received
where status is status object. OUTPUT



MPI_Send and MPI_Recv is a blocking command

hellow MPI

this is the code what i ised in the hello word

#include<stdio.h>
#include <mpi.h>
int main(int argc, char *argv[])
{
   int nprocs, myproc;
   MPI_Init( &argc, &argv );
   MPI_Comm_size( MPI_COMM_WORLD, &nprocs );
   MPI_Comm_rank( MPI_COMM_WORLD, &myproc );
   printf("Hola soy %d  de %d \n\n",myproc,nprocs);
   MPI_Finalize();
   return 0;
}



how i can install MPI in my computer?

bien empesare a modo de la instaciòn basica desde cero.

tenemos esta interface

bien seguiremos los siguientes pasos asta donde nos llevan


primero descargamos el tar en la pagina oficial
http://www.mpich.org/downloads/


bien ahora procedemos a descomprimirlo
 tar -xzf mpich2-1.4.tar.gz
nos situamos despues en el directorio

cd mpi....
Antes creamos una carpeta de instalacion,
mkdir intalacion.

instalacmos fortram primero
sudo apt-get install gfortran 
bien ahora

./configure --prefix "/home/fablab/carlos/instalacion"

bien ahora un make :P
dicen que esto tardara bien ahora son las 4 y 20 veamos cuanto tarda.
 bien no tardo mucho son las 4 y 27 y ya esta.

make
sudo make install

export PATH="$PATH:/home/$USER/.openmpi/bin"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/$USER/.openmpi/lib/"

ahora lo guardamos para futuras secciones

echo export PATH="$PATH:/home/$USER/.openmpi/bin" >> /home/$USER/.bashrc
echo export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/$USER/.openmpi/lib/"
>> /home/$USER/.bashrc


Eso es todo
no muy complicado