From 329c9f6217af87786d253a12e0f33f3470e8b404 Mon Sep 17 00:00:00 2001 From: David Kaufmann Date: Thu, 26 Jan 2012 22:45:39 +0100 Subject: [PATCH] add mpi --- openmp/scan/Makefile | 20 ++++++++++++++++++++ openmp/scan/scan.c | 37 +++++++++++++++++++++++++++++++++++++ openmp/scan/scan.h | 3 +++ 3 files changed, 60 insertions(+) create mode 100644 openmp/scan/Makefile create mode 100644 openmp/scan/scan.c create mode 100644 openmp/scan/scan.h diff --git a/openmp/scan/Makefile b/openmp/scan/Makefile new file mode 100644 index 0000000..8b34472 --- /dev/null +++ b/openmp/scan/Makefile @@ -0,0 +1,20 @@ +# GCC Makefile + +CC = mpicc +CFLAGS = -pedantic -Wall -ggdb -fopenmp --std=c99 -O3 ${MYFLAGS} +LDFLAGS = -fopenmp + +all: build/scan + +build/scan: build/scan.o + $(CC) -o $@ $? $(LDFLAGS) + +build/%.o: %.c mkdir + $(CC) $(CFLAGS) -c $< -o $@ + +mkdir: + mkdir -p build + +.PHONY: clean +clean: + rm -rf build diff --git a/openmp/scan/scan.c b/openmp/scan/scan.c new file mode 100644 index 0000000..ec1029e --- /dev/null +++ b/openmp/scan/scan.c @@ -0,0 +1,37 @@ +/* + * Inclusive scan + */ + +#include +#include +#include "scan.h" +#include + +#define KEY 1234 // tag for control messages + +int main(int argc, char *argv[]) +{ + int rank, size; + int prev; + char name[MPI_MAX_PROCESSOR_NAME]; + int nlen; + + MPI_Init(&argc,&argv); + + // get rank and size from communicator + MPI_Comm_size(MPI_COMM_WORLD,&size); + MPI_Comm_rank(MPI_COMM_WORLD,&rank); + + MPI_Get_processor_name(name,&nlen); + + if (rank==0) { + printf("Rank %d initializing, total %d\n",rank,size); + } else { + MPI_Recv(&prev,1,MPI_INT,rank-1,HELLO,MPI_COMM_WORLD,MPI_STATUS_IGNORE); + printf("Rank %d on %s received from %d, passing on\n",rank,name,prev); + } + if (rank+1