diff --git a/19-20/mpi_examples/basic_send_omp/Makefile b/19-20/mpi_examples/basic_send_omp/Makefile new file mode 100644 index 0000000..119c9df --- /dev/null +++ b/19-20/mpi_examples/basic_send_omp/Makefile @@ -0,0 +1,24 @@ +# The pre-processor and compiler options. +#OPTIONS +CC = mpic++ +CFLAGS = -Wall -fopenmp -std=c++11 +LDFLAGS = -lgomp -lz + +#---------- + +EXE = bin + +OBJS = $(patsubst %.cpp,%.o,$(wildcard *.cpp)) + +#---------- + +$(EXE): $(OBJS) + $(CC) $(OBJS) $(LIB_DIRS) $(LLIBS)$(LDFLAGS) -o $(EXE) + +$(OBJS): %.o : %.cpp + $(CC) $(CFLAGS) -c $< + +#---------- + +clean: + rm -f *.o *.*~ *~ $(EXE) diff --git a/19-20/mpi_examples/basic_send_omp/main.cpp b/19-20/mpi_examples/basic_send_omp/main.cpp new file mode 100755 index 0000000..abfaaa7 --- /dev/null +++ b/19-20/mpi_examples/basic_send_omp/main.cpp @@ -0,0 +1,31 @@ +#include +#include "mpi.h" +#include "omp.h" + +#include +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 << "> " < Number: " << received << " Received by "<< node_name<< std::endl; + } + MPI_Finalize(); +} + diff --git a/19-20/mpi_examples/basic_send_omp/runJob.sh b/19-20/mpi_examples/basic_send_omp/runJob.sh new file mode 100644 index 0000000..bf29cfa --- /dev/null +++ b/19-20/mpi_examples/basic_send_omp/runJob.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# This script can take multiple parameters +# The first is the executable (required) any others would be passed as paremeter# to that executable + +if [ "$1" == "" ]; then + echo "Positional parameter 1 is empty" +else +mpirun -hostfile /etc/pdsh/machines --map-by ppr:1 node $1 $2 $3 + +fi