daily pastebin goal
33%
SHARE
TWEET

Untitled

a guest May 16th, 2018 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  ============================================================================
  3.  Name        : labor6.c
  4.  Author      : dan
  5.  Version     :
  6.  Copyright   : Your copyright notice
  7.  Description : Hello MPI World in C
  8.  ============================================================================
  9.  */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <math.h>
  14. #include "mpi.h"
  15.  
  16. int main(int argc, char **argv) {
  17.     int masca, dest, sursa,doi_la_k,k;
  18.     int count, myrank;
  19.     /* tag for messages */
  20.     char mesaj[20]="Hello";/* storage for message */
  21.     MPI_Init(&argc, &argv);
  22.     MPI_Status status;
  23.     MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
  24.     MPI_Comm_size(MPI_COMM_WORLD, &count);
  25.     masca=(1<<3)-1;
  26.     /* initializeaza cu 1 toti bitii mastii */
  27.     for (k=2;k>=0;k--) {
  28.         doi_la_k=(1<<k);
  29.         masca=(masca^doi_la_k);
  30.         /* seteaza pe 0 al k-lea bit al mastii */
  31.         if ((myrank & masca)==0) {
  32.             /* daca ultimii k biti sunt 0 */
  33.             if ((myrank & doi_la_k)==0) {
  34.                 dest=myrank^doi_la_k;
  35.                 MPI_Send(mesaj, strlen(mesaj) + 1, MPI_CHAR, dest, 99,MPI_COMM_WORLD);
  36.                 printf("%d trimite catre %d \n", myrank,dest);
  37.             } else {
  38.                 sursa = myrank^doi_la_k;
  39.                 MPI_Recv(mesaj, strlen(mesaj) + 1, MPI_CHAR, sursa, 99,MPI_COMM_WORLD, &status);
  40.             }
  41.         }
  42.     }
  43.     MPI_Finalize();
  44.     return 0;
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top