From 9dd4c7fd4c87053324c01d122175e5d68b481f02 Mon Sep 17 00:00:00 2001 From: Christoph Niethammer Date: Tue, 6 Mar 2012 15:07:26 +0000 Subject: [PATCH] Added test for fastflow installation. --- tests/libs/fastflow/Makefile | 18 ++++++++ tests/libs/fastflow/matrix.cpp | 84 ++++++++++++++++++++++++++++++++++ tests/libs/fastflow/test.sh | 13 ++++++ 3 files changed, 115 insertions(+) create mode 100644 tests/libs/fastflow/Makefile create mode 100644 tests/libs/fastflow/matrix.cpp create mode 100755 tests/libs/fastflow/test.sh diff --git a/tests/libs/fastflow/Makefile b/tests/libs/fastflow/Makefile new file mode 100644 index 0000000..ce01657 --- /dev/null +++ b/tests/libs/fastflow/Makefile @@ -0,0 +1,18 @@ +CXX = g++ +CXXFLAGS = -I $(FASTFLOW_INC_DIR) -pthread +NPES=$(shell cat /proc/cpuinfo | grep -c processor) + +.PHONY: default all +default: all +all: matrix matrix-ff + +matrix: matrix.cpp + $(CXX) $(CXXFLAGS) -o $@ $< + +matrix-ff: matrix.cpp + $(CXX) $(CXXFLAGS) -DFASTFLOW -DNWORKERS=$(NPES) -o $@ $< + +.PHONY: clean +clean: + rm -f matrix matrix-ff + rm -f matrix.dat matrix-ff.dat diff --git a/tests/libs/fastflow/matrix.cpp b/tests/libs/fastflow/matrix.cpp new file mode 100644 index 0000000..0509923 --- /dev/null +++ b/tests/libs/fastflow/matrix.cpp @@ -0,0 +1,84 @@ +#include +#include + +using namespace std; + +#define N 1024 +int A[N][N], B[N][N], C[N][N]; + + +#ifdef FASTFLOW +#include + +struct task_t { + task_t(int i, int j):i(i),j(j) {} + int i; + int j; +}; + +class Worker : public ff::ff_node{ +public: + void * svc(void * task){ + task_t * t = (task_t *) task; + + int _C = 0; + for(int k = 0; k < N; k++) + _C += A[t->i][k]*B[k][t->j]; + C[t->i][t->j] = _C; + + delete t; + return GO_ON; + } +}; + +#endif + + +int main() { + +#ifdef FASTFLOW + ff::ff_farm<> farm(true); + vector w; + cout << "Using " << NWORKERS << " workers." << endl; + for(int i = 0; i < NWORKERS; i++) + w.push_back(new Worker); + farm.add_workers(w); + farm.run_then_freeze(); +#endif + + + for(int i = 0; i < N; i++) { + for(int j = 0; j < N; j++) { +#ifdef FASTFLOW + task_t * task = new task_t(i,j); + farm.offload(task); +#else + int _C = 0; + for(int k = 0; k < N; k++) + _C += A[i][k]*B[k][j]; + C[i][j] = _C; +#endif + } + } + +#ifdef FASTFLOW + farm.offload((void *) ff::FF_EOS); + farm.wait(); +#endif + + + string filename; +#ifdef FASTFLOW + filename = "matrix-ff.dat"; +#else + filename = "matrix.dat"; +#endif + fstream off; + off.open(filename.c_str(), fstream::out); + for(int i = 0; i < N; i ++) { + for( int j = 0; j < N; j++) + off << C[i][j]; + } + off.close(); + return 0; +} diff --git a/tests/libs/fastflow/test.sh b/tests/libs/fastflow/test.sh new file mode 100755 index 0000000..9c410d6 --- /dev/null +++ b/tests/libs/fastflow/test.sh @@ -0,0 +1,13 @@ +make +./matrix +./matrix-ff +diff matrix.dat matrix-ff.dat +ret=$? + +if [ $ret != 0 ] ; then + echo "Failed" +else + echo "Success" + make clean +fi +