#include <stdio.h>
#include "mpi.h"
main(int argc, char **argv){
int size, rank, error, i,j,proc=0;
int izq,der,up, down, a,b;
int p=6,q=2,m=5,n=6;
int m_proc[p][q];
int datos[m+2][n];
char dato;
MPI_Status status;
error=MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
for(i=0;i<m+2;i++){
for(j=0;j<n;j++){
datos[i][j]=rank;
}
}
for(i=0;i<p;i++){
for(j=0;j<q;j++){
if(rank==proc){
a=i;
b=j;
}
m_proc[i][j]=proc;
proc++;
}
}
if(b+1==q)
der= m_proc[a][0];
else
der=m_proc[a][b+1];
if(b-1<0)
izq= m_proc[a][q-1];
else
izq= m_proc[a][b-1];
if(a-1<0)
up= m_proc[p-1][b];
else
up= m_proc[a-1][b];
if(a+1==p)
down= m_proc[0][b];
else
down= m_proc[a+1][b];
if(a%2){
MPI_Send(&datos[1][0], n, MPI_INT, up , 0, MPI_COMM_WORLD);
MPI_Send(&datos[m-2][0], n, MPI_INT,down , 0, MPI_COMM_WORLD);
MPI_Recv(&datos[m-1][0], n, MPI_INT, down, 0, MPI_COMM_WORLD, &status);
MPI_Recv(&datos[0][0], n, MPI_INT, up, 0, MPI_COMM_WORLD, &status);
}else{
MPI_Recv(&datos[m-1][0], n, MPI_INT, down, 0, MPI_COMM_WORLD, &status);
MPI_Recv(&datos[0][0], n, MPI_INT, up, 0, MPI_COMM_WORLD, &status);
MPI_Send(&datos[1][0], n, MPI_INT, up, 0, MPI_COMM_WORLD);
MPI_Send(&datos[m-2][0], n, MPI_INT, down, 0, MPI_COMM_WORLD);
}
printf("Procceso No: %d\nEnviados: Renglon_1:%d Renglon n-2:%d \nRecibidos: Renglon_0:%d Renglon n-1:%d\n\n",rank,datos[1][0],datos[m-2][0],datos[0][0],datos[m-1][0]);
error=MPI_Finalize();
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.