fork download
  1.  
  2. #include "mpi.h"
  3. #include <stdio.h>
  4. #include <string.h>
  5. int main(int argc, char *argv[]) {
  6. int i,id_rank,nop;
  7. char data[50];
  8. MPI_Status st;
  9. MPI_Init(&argc,&argv);
  10. MPI_Comm_size(MPI_COMM_WORLD, &nop);
  11. MPI_Comm_rank(MPI_COMM_WORLD, &id_rank);
  12. if(id_rank==0)
  13. {
  14. printf("Enter the value to be sent to the receiver\n");
  15. scanf("%s",data);
  16. int l=strlen(data);
  17. MPI_Ssend(&data,strlen(data),MPI_CHAR,1,1,MPI_COMM_WORLD);
  18. fprintf(stdout,"i %d process have sent the word %s \n",id_rank,data);
  19. fflush(stdout);
  20. }
  21. else
  22. {
  23. MPI_Recv(&data,7,MPI_CHAR,1,1,MPI_COMM_WORLD,&st);
  24. fprintf(stdout, " the data by process %d received is %s\n",id_rank,data);
  25. for(i=0;i<strlen(data);i++)
  26. {
  27. if(data[i]>=65 &&data[i]<=90)
  28. data[i]+=32;
  29. else
  30. data[i]-=32;
  31. }
  32. MPI_Send(&data,strlen(data),MPI_CHAR,0,1,MPI_COMM_WORLD);
  33. fflush(stdout);
  34. }
  35. if(id_rank==0)
  36. {
  37.  
  38. //scanf("%s",data);
  39. MPI_Recv(&data,7,MPI_CHAR,1,1,MPI_COMM_WORLD,&st);
  40. fprintf(stdout, " the toggled data received is by process %d %s\n",id_rank,data);
  41. //fprintf(stdout,"i %d process have sent the word %s \n",id_rank,data);
  42. fflush(stdout);
  43. }
  44. fflush(stdout);
  45. MPI_Finalize();
  46. return 0;
  47. }
  48.  
  49.  
  50.  
Success #stdin #stdout #stderr 0.29s 40580KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted