Herramientas Personales
Usted está aquí: Inicio / Investigación / Laboratorio de Sistemas Complejos / SCMP / gather.c

gather.c

C source code icon gather.c — C source code, 683 bytes

Contenido del Archivo

#include <stdlib.h>
#include <stdio.h>
#include "mpi.h"

#define LENGTH 24

int main(int argc, char* argv[]) {
  int i, np, myRank;
  int root = 0;

  int x[LENGTH];        
  int y[LENGTH];        

  MPI_Init(&argc, &argv);
  MPI_Comm_size(MPI_COMM_WORLD, &np);
  MPI_Comm_rank(MPI_COMM_WORLD, &myRank);

  
  for (i=0; i<LENGTH/np; i++) {
    x[i] = myRank;
  }

  if (myRank == 0) {
    
    MPI_Gather(x, LENGTH/np, MPI_INT, y, LENGTH/np, MPI_INT, root, MPI_COMM_WORLD);

    for (i=0; i<LENGTH; i++) {
      printf(" %d", y[i]);
    }
    printf("\n\n");

  } else {
    MPI_Gather(x, LENGTH/np, MPI_INT, y, LENGTH/np, MPI_INT, root, MPI_COMM_WORLD);
  }

  MPI_Finalize();
}