Added test for fastflow installation.
This commit is contained in:
parent
4d98166827
commit
9dd4c7fd4c
3 changed files with 115 additions and 0 deletions
18
tests/libs/fastflow/Makefile
Normal file
18
tests/libs/fastflow/Makefile
Normal file
|
@ -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
|
84
tests/libs/fastflow/matrix.cpp
Normal file
84
tests/libs/fastflow/matrix.cpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define N 1024
|
||||
int A[N][N], B[N][N], C[N][N];
|
||||
|
||||
|
||||
#ifdef FASTFLOW
|
||||
#include <ff/farm.hpp>
|
||||
|
||||
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<ff::ff_node *> 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;
|
||||
}
|
13
tests/libs/fastflow/test.sh
Executable file
13
tests/libs/fastflow/test.sh
Executable file
|
@ -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
|
||||
|
Loading…
Reference in a new issue