comunication_func.c 1.05 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <stdlib.h>
#include <stdio.h>
#include <mpi.h>
#include "comunication_func.h"

/*
 * Realiza una comunicación punto a punto en orden
 * El proceso X envia a X+1 y recibe de X-1
 */
void point_to_point(int myId, int numP, int root, MPI_Comm comm, char *array, int qty) {
  int prev, next;
  next = (myId+1) % numP;
  prev = (myId == 0 ? numP-1 : myId-1);

  if(myId == root) {
    MPI_Send(array, qty, MPI_CHAR, next, 99, comm);
    MPI_Recv(array, qty, MPI_CHAR, prev, 99, comm, MPI_STATUS_IGNORE);
  } else {
    MPI_Recv(array, qty, MPI_CHAR, prev, 99, comm, MPI_STATUS_IGNORE);
    MPI_Send(array, qty, MPI_CHAR, next, 99, comm);
  }
}
23
24
25
26
27
28
29
30
31
32
33
34
35

void point_to_point_inter(int myId, int numP, MPI_Comm comm, char *array, int qty) {
  int target;
  target = (myId + numP/2)%numP;

  if(myId < numP/2) {
    MPI_Send(array, qty, MPI_CHAR, target, 99, comm);
    //MPI_Recv(array, qty, MPI_CHAR, target, 99, comm, MPI_STATUS_IGNORE);
  } else {
    MPI_Recv(array, qty, MPI_CHAR, target, 99, comm, MPI_STATUS_IGNORE);
    //MPI_Send(array, qty, MPI_CHAR, target, 99, comm);
  }
}