geovanny_mendez

Paralelización bucle open mpi

Jun 2nd, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. /**********************************************************************************
  2.  circu.c paralelizacion MPI de un bucle
  3. **********************************************************************************/
  4. #include <mpi.h>
  5. #include <stdio.h>
  6. #define DECBIN(n,i) ((n&(1<<i))?1:0)
  7. void test (int pid, int z)
  8. {
  9.      int v[16], i;
  10.      for (i=0; i<16; i++) {
  11.         v[i] = DECBIN(z,i);
  12.      }
  13.  
  14.      if ((v[0] || v[1]) && (!v[1] || !v[3]) && (v[2] || v[3])
  15.      && (!v[3] || !v[4]) && (v[4] || !v[5])
  16.      && (v[5] || !v[6]) && (v[5] || v[6])
  17.      && (v[6] || !v[15]) && (v[7] || !v[8])
  18.      && (!v[7] || !v[13]) && (v[8] || v[9])
  19.      && (v[8] || !v[9]) && (!v[9] || !v[10])
  20.      && (v[9] || v[11]) && (v[10] || v[11])
  21.      && (v[12] || v[13]) && (v[13] || !v[14])
  22.      && (v[14] || v[15]))
  23.      {
  24.          printf(" %d) %d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d (%d)\n", pid, v[15],v[14],v[13],
  25.          v[12],v[11],v[10],v[9],v[8],v[7],v[6],v[5],v[4],v[3],v[2],v[1],v[0], z);
  26.          fflush(stdout);
  27.      }
  28. }
  29.  
  30. int main (int argc, char *argv[])
  31. {
  32.      int i, pid, npr;
  33.  
  34.      MPI_Init(&argc, &argv);
  35.  
  36.          MPI_Comm_size(MPI_COMM_WORLD, &npr);
  37.          MPI_Comm_rank(MPI_COMM_WORLD, &pid);
  38.  
  39.          for (i=pid; i<65536; i += npr) {
  40.             test(pid, i);
  41.          }
  42.  
  43.      MPI_Finalize();
  44.      return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment