Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<mpi.h>
- #include<stdio.h>
- #include<stdlib.h>
- #include<iostream>
- #include<conio.h>
- using namespace std;
- int main(int argc, char** argv)
- {
- int rank,size,len,handle;
- char str[50],str1[50],str2[50];
- MPI_Status status;
- MPI_Init(&argc,&argv);
- MPI_Comm_rank(MPI_COMM_WORLD,&rank);
- MPI_Comm_size(MPI_COMM_WORLD,&size);
- if(rank==0)
- {
- cout<<"Enter a string that is a multiple of 3\n";
- fflush(stdout);
- gets(str);
- fflush(stdin);
- len = strlen(str);
- handle = len/size;
- for(int i=1;i<size;i++)
- MPI_Send(&handle,1,MPI_INT,i,i,MPI_COMM_WORLD);
- }
- if(rank!=0)
- {
- MPI_Recv(&handle,1,MPI_INT,0,rank,MPI_COMM_WORLD,&status);
- }
- MPI_Scatter(&str[0],handle,MPI_CHAR,&str1[0],handle,MPI_CHAR,0,MPI_COMM_WORLD);
- for(int i=0;i<handle;i++)
- {
- str1[i] = str1[i] + 1;
- }
- MPI_Gather(&str1[0],handle,MPI_CHAR,&str2[0],handle,MPI_CHAR,0,MPI_COMM_WORLD);
- if(rank==0)
- {
- cout<<"Output is:\n";
- str2[len]='\0';
- puts(str2);
- fflush(stdout);
- }
- MPI_Finalize();
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement