Initial commit

This commit is contained in:
Matthias
2017-04-11 15:49:55 +02:00
commit 3d8f381bae
106 changed files with 4407 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
#define Idx2D(x, y) (x)*(N+1)+(y)
double* mat_a = sin->mat_a.getValue();
long chunksize = sin->chunksize.getValue();
long N = sin->N.getValue();
long i_min = sin->i.getValue();
long i_max = std::min(i_min + chunksize, 2*N-2);
//fprintf(stderr, "i = [%d, %d)\n", i_min, i_max);
for(long i=i_min; i<i_max; ++i) {
if(i<N) {
for(long j=1; j<=i; ++j) {
long x = i-j+1;
double old = mat_a[Idx2D(x, j)];
mat_a[Idx2D(x, j)] = 0.8*old + 0.2*0.25*mat_a[Idx2D(x-1, j)]*mat_a[Idx2D(x+1, j)]*mat_a[Idx2D(x, j-1)]*mat_a[Idx2D(x, j+1)];
}
} else {
for(long j=i-N+2; j<N; ++j) {
long x = i-j+1;
double old = mat_a[Idx2D(x, j)];
mat_a[Idx2D(x, j)] = 0.9*old + 0.1*0.25*mat_a[Idx2D(x-1, j)]*mat_a[Idx2D(x+1, j)]*mat_a[Idx2D(x, j-1)]*mat_a[Idx2D(x, j+1)];
}
}
}
sout->result.setValue(mat_a);
+4
View File
@@ -0,0 +1,4 @@
name=AtomicActivity
entries=1
entry.0=atomic1.code
+2
View File
@@ -0,0 +1,2 @@
#include <omp.h>
#include <boost/program_options.hpp>
+63
View File
@@ -0,0 +1,63 @@
long N = 2000;
long iterMax = 100;
long chunksize = -1;
bool isHelp = false;
bool disableCheck = false;
boost::program_options::options_description opts("Wavefront Options");
opts.add_options()
("help", "Print help message.")
("itermax", boost::program_options::value<long>(), "Iteration count.")
("n", boost::program_options::value<long>(), "Array size (n+1 x n+1).")
("chunksize", boost::program_options::value<long>(), "Chunk size.")
("disable-check", "Don't check for correctness.");
boost::program_options::variables_map vm;
auto parsed = boost::program_options::command_line_parser(argc, argv).options(opts).allow_unregistered().run();
boost::program_options::store(parsed, vm);
boost::program_options::notify(vm);
if (vm.count("help")) {
std::cerr << opts << std::endl;
isHelp = true;
} else {
if (vm.count("itermax")) {
iterMax = vm["itermax"].as<long>();
}
if (vm.count("n")) {
N = vm["n"].as<long>();
}
if (vm.count("chunksize")) {
chunksize = vm["chunksize"].as<long>();
}
if (vm.count("disable-check")) {
disableCheck = true;
}
}
long _2N2 = 2*N-2;
if (chunksize <= 0) {
chunksize = (_2N2/8)+1;
}
if (!isHelp) {
std::cerr << "itermax = " << iterMax << std::endl;
std::cerr << "N = " << N << std::endl;
std::cerr << "chunksize = " << chunksize << std::endl;
if (disableCheck) {
std::cerr << "disableCheck = true" << std::endl;
} else {
std::cerr << "disableCheck = false" << std::endl;
}
}
wfInput.iterMax.setValue(iterMax);
wfInput.N.setValue(N);
wfInput._2N2.setValue(_2N2);
wfInput.chunksize.setValue(chunksize);
#define Idx2D(x, y) (x)*(N+1)+(y)
double* mat_a = (double*)malloc(sizeof(double)*(N+1)*(N+1));
double* mat_b = (double*)malloc(sizeof(double)*(N+1)*(N+1));
//srand(time(NULL));
srand(20);
for(int i=0; i<N; ++i) {
for(int j=0; j<N; ++j) {
mat_a[Idx2D(i, j)] = ((double)(rand() % 100) / (double)RAND_MAX) * 1000000.0;
mat_b[Idx2D(i, j)] = mat_a[Idx2D(i, j)];
}
}
wfInput.mat_a.setValue(mat_a);
+47
View File
@@ -0,0 +1,47 @@
if (!disableCheck) {
double t = omp_get_wtime();
omp_set_schedule(omp_sched_dynamic, chunksize);
#pragma omp parallel
for(int iter=0; iter<iterMax; ++iter) {
//#pragma omp for schedule(dynamic,32)
#pragma omp for schedule(runtime)
for(int i=1; i<2*N-2; ++i) {
if(i<N) {
for(int j=1; j<=i; ++j) {
int x = i-j+1;
double old = mat_b[Idx2D(x, j)];
mat_b[Idx2D(x, j)] = 0.8*old + 0.2*0.25*mat_b[Idx2D(x-1, j)]*mat_b[Idx2D(x+1, j)]*mat_b[Idx2D(x, j-1)]*mat_b[Idx2D(x, j+1)];
}
} else {
for(int j=i-N+2; j<N; ++j) {
int x = i-j+1;
double old = mat_b[Idx2D(x, j)];
mat_b[Idx2D(x, j)] = 0.9*old + 0.1*0.25*mat_b[Idx2D(x-1, j)]*mat_b[Idx2D(x+1, j)]*mat_b[Idx2D(x, j-1)]*mat_b[Idx2D(x, j+1)];
}
}
}
}
printf("OMP Complete: %8.4lf\n", omp_get_wtime()-t);
int ok = 0;
int nok = 0;
int nan = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (isnan(mat_a[Idx2D(i, j)]) || isinf(mat_a[Idx2D(i, j)]) || isnan(mat_b[Idx2D(i, j)]) || isinf(mat_b[Idx2D(i, j)])) {
nan++;
} else if (fabs(mat_a[Idx2D(i, j)] - mat_b[Idx2D(i, j)]) < (double)0.000001) {
ok++;
} else {
//printf("diff[%d,%d]: %.40lf - %.40lf = %.40lf\n", i,j,mat_a[Idx2D(i, j)], mat_b[Idx2D(i, j)], mat_a[Idx2D(i, j)] - mat_b[Idx2D(i, j)]);
nok++;
}
}
}
printf("nan: %d, ok: %d, nok: %d\n", nan, ok, nok);
if (nok != 0) {
#include <sstream>
std::stringstream ss;
ss << "Test Failure: nok [" << nok << "] is not zero.";
throw wfr::exception::wfr_fatal_error(ss.str());
}
}