comunication_func.c 1.36 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
void point_to_point_inter(int myId, int numP, MPI_Comm comm, char *array, char *r_array, int qty) {
25
26
  int target;
  target = (myId + numP/2)%numP;
27
28
  MPI_Sendrecv(array, qty, MPI_CHAR, target, 99, r_array, qty, MPI_CHAR, target, 99, comm, MPI_STATUS_IGNORE);
}
29

30
31
32
void point_to_point_asynch_inter(int myId, int numP, MPI_Comm comm, char *array, char *r_array, int qty, MPI_Request *reqs) {
  int target;
  target = (myId + numP/2)%numP;
33
  if(myId < numP/2) {
34
35
    MPI_Isend(array, qty, MPI_CHAR, target, 99, comm, &(reqs[0]));
    MPI_Irecv(r_array, qty, MPI_CHAR, target, 99, comm, &(reqs[1]));
36
  } else {
37
38
    MPI_Irecv(r_array, qty, MPI_CHAR, target, 99, comm, &(reqs[0]));
    MPI_Isend(array, qty, MPI_CHAR, target, 99, comm, &(reqs[1]));
39
40
  }
}