From 22cd83bfe64f30db2618988e2bc9587d6341815d Mon Sep 17 00:00:00 2001 From: Vanessa Vichi Date: Wed, 24 Apr 2024 16:50:48 +0200 Subject: [PATCH] added --- Makefile | 4 +++- easysendrecv.c | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 easysendrecv.c diff --git a/Makefile b/Makefile index 8946058..54bb52f 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,11 @@ MPICC = mpicc CFLAGS += -g -all: example example2 +all: example example2 easysendrecv example: example.c $(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@ example2: example2.c $(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@ +easysendrecv: easysendrecv.c + $(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@ clean: rm -f example example2 diff --git a/easysendrecv.c b/easysendrecv.c new file mode 100644 index 0000000..13f8bde --- /dev/null +++ b/easysendrecv.c @@ -0,0 +1,17 @@ +#include "mpi.h" +#include +#include +int main( int argc, char **argv){ +char message[20]; int myrank; MPI_Status status; +MPI_Init( &argc, &argv ); +MPI_Comm_rank( MPI_COMM_WORLD, &myrank ); +if (myrank == 0){ /* code for process zero */ +strcpy(message,"Hello, there"); +MPI_Send(message, strlen(message)+1, MPI_CHAR, 1, 99, MPI_COMM_WORLD); +} +else if (myrank == 1){ /* code for process one */ +MPI_Recv(message, 20, MPI_CHAR, 0, 99, MPI_COMM_WORLD, &status); +printf("received :%s:\n", message); +} +MPI_Finalize(); +return 0; }