16.04.2014 Views

Administración avanzada de GNU/Linux (PDF) - SW Computación

Administración avanzada de GNU/Linux (PDF) - SW Computación

Administración avanzada de GNU/Linux (PDF) - SW Computación

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ª FUOC • XP04/90785/00019<br />

Software libre<br />

Ejecución Mpich: mpirun.mpich -np N.º_procesos srtest<br />

(solicitará la contraseña [N.º procesos - 1] veces si<br />

no se tiene el acceso directo por ssh).<br />

Ejecución LAM:<br />

mpirun np N.º_procesos srtest<br />

(<strong>de</strong>be ser un usuario diferente <strong>de</strong> root).<br />

#inclu<strong>de</strong> “mpi.h”<br />

#inclu<strong>de</strong> <br />

#<strong>de</strong>fine BUFLEN 512<br />

int main(int argc, char *argv[]) {<br />

ANOTACIONES<br />

int myid, numprocs, next, namelen;<br />

char buffer[BUFLEN], processor_name[MPI_MAX_PROCESSOR_NAME];<br />

MPI_Status status;<br />

MPI_Init(&argc,&argv);<br />

/* Debe ponerse antes <strong>de</strong> otras llamadas MPI, siempre */<br />

MPI_Comm_size(MPI_COMM_WORLD,&numprocs);<br />

MPI_Comm_rank(MPI_COMM_WORLD,&myid);<br />

/*Integra el proceso en un grupo <strong>de</strong> comunicaciones*/<br />

MPI_Get_processor_name(processor_name,&namelen);<br />

/*Obtiene el nombre <strong>de</strong>l procesador*/<br />

fprintf(st<strong>de</strong>rr,”Proceso %d sobre %s\n”, myid, processor_name);<br />

strcpy(buffer,”Hola Pueblo”);<br />

if (myid ==numprocs1) next = 0;<br />

else next = myid+1;<br />

if (myid ==0) {<br />

/*Si es el inicial, envía string <strong>de</strong> buffer*/.<br />

printf(“%d Envío ‘%s’ \n”,myid,buffer);<br />

MPI_Send(buffer, strlen(buffer)+1, MPI_CHAR, next, 99, MPI_COMM_WORLD);<br />

/*Blocking Send, 1 o :buffer, 2 o :size, 3 o :tipo, 4 o :<strong>de</strong>stino, 5 o :tag, 6 o<br />

:contexto*/<br />

/*MPI_Send(buffer, strlen(buffer)+1, MPI_CHAR, MPI_PROC_NULL, 299,MPI_COMM_WORLD);*/<br />

printf(“%d recibiendo \n”,myid);<br />

/* Blocking Recv, 1 o :buffer, 2 o :size, 3 o :tipo, 4 o :fuente, 5 o :tag, 6 o<br />

:contexto, 7 o :status*/<br />

}<br />

MPI_Recv(buffer, BUFLEN, MPI_CHAR, MPI_ANY_SOURCE, 99, MPI_COMM_WORLD,&status);<br />

printf(“%d recibió ‘%s’ \n”,myid,buffer) }<br />

else {<br />

printf(“%d recibiendo \n”,myid);<br />

MPI_Recv(buffer, BUFLEN, MPI_CHAR, MPI_ANY_SOURCE, 99, MPI_COMM_WORLD,status);<br />

/*MPI_Recv(buffer, BUFLEN, MPI_CHAR, MPI_PROC_NULL, 299,MPI_COMM_WORLD,&status);*/<br />

printf(“%d recibió ‘%s’ \n”,myid,buffer);<br />

MPI_Send(buffer, strlen(buffer)+1, MPI_CHAR, next, 99, MPI_COMM_WORLD);<br />

printf(“%d envió ‘%s’ \n”,myid,buffer);}<br />

MPI_Barrier(MPI_COMM_WORLD);<br />

/*Sincroniza todos los procesos*/<br />

MPI_Finalize();<br />

/*Libera los recursos y termina*/<br />

return (0);<br />

430

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!