Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ab0475@holly.coventry.ac.uk.69549 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <iostream> | ||
#include "mpi.h" | ||
#include "omp.h" | ||
|
||
#include <cstring> | ||
int main(int argc, char** argv) { | ||
|
||
// Initialize the MPI environment | ||
MPI_Init(NULL, NULL); | ||
char node_name[MPI_MAX_PROCESSOR_NAME]; | ||
int rank,size, namelen; | ||
int send_num = 5; | ||
int received = 0; | ||
MPI_Comm_rank(MPI_COMM_WORLD, &rank); | ||
MPI_Comm_size(MPI_COMM_WORLD, &size); | ||
MPI_Get_processor_name(node_name, &namelen); | ||
memset(node_name+namelen,0,MPI_MAX_PROCESSOR_NAME-namelen); | ||
int dest = 1;//atoi(argv[2]); // change to command line inputs again if you want to vary these | ||
int src = 0; //atoi(argv[1]); | ||
if (rank == src) { | ||
MPI_Send(&send_num, 1, MPI_INT, dest, 0, MPI_COMM_WORLD); | ||
std::cout << "> " <<node_name<<" Sent " << send_num << " To node"<< dest << std::endl; | ||
} | ||
if(rank == dest){ | ||
std::cout << " hello from "<< node_name<< std::endl; | ||
MPI_Recv(&received, 1, MPI_INT, src, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); | ||
|
||
// processing | ||
std::cout << "> Number: " << received << " Received by "<< node_name<< std::endl; | ||
|
||
MPI_Send(&send_num, 1, MPI_INT, dest, 0, MPI_COMM_WORLD); | ||
std::cout << "> " <<node_name<<" Sent " << send_num << " To node"<< dest << std::endl; | ||
cond = true; | ||
} | ||
|
||
if (rank == src && cond == true) { | ||
MPI_Recv(&received, 1, MPI_INT, src, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); | ||
|
||
} | ||
MPI_Finalize(); | ||
} | ||
|