Skip to content

Instantly share code, notes, and snippets.

@Sutil
Created January 15, 2016 23:00
Show Gist options
  • Save Sutil/9628afc0489e3656a0aa to your computer and use it in GitHub Desktop.
Save Sutil/9628afc0489e3656a0aa to your computer and use it in GitHub Desktop.
#include "stddef.h"
#include "mpi.h"
#include "stdio.h"
#define LIMITE 10
int count = 0;
void main(int argc, char *argv[]){
int rank, size, type = 99;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
printf("Começou %d\n" rank);
int partner = 1 - rank;
while(count < LIMITE){
if(rank == count % 2){
count++;
MPI_Send(&count, 1, MPI_INT, partner, 0, MPI_COMM_WORLD);
printf("processo %d inrementou count para %d", rank, count);
} else {
MPI_Recv(&count, 1, MPI_INT, partner, 0, MPI_COMM_WORLD, &status);
printf("processo %d recebeu count com valor %d", rank, count);
}
}
printf("fianlizou");
MPI_Finalize();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment