GitHub Viewer
#include "dnn.hpp"
#include
void omp_dnn(MNIST_DNN& D, const unsigned num_iteration) {
const int num_layers = D.num_layers();
auto dep_f = new int [num_iteration];
auto dep_b = new int [num_iteration*num_layers];
auto dep_u = new int [num_iteration*num_layers];
#pragma omp parallel
{
#pragma omp single
{
for(auto i=0u; i=0; j--) {
if(j == num_layers-1) {
#pragma omp task depend (in: dep_f[i]) depend (out: dep_b[i*num_layers + j]) firstprivate(j) shared(D, IMAGES)
{
backward_task(D, j, IMAGES);
}
}
else {
#pragma omp task depend (in: dep_b[i*num_layers + j + 1]) depend (out: dep_b[i*num_layers + j]) firstprivate(j) shared(D, IMAGES)
{
backward_task(D, j, IMAGES);
}
}
}
// Update tasks
for(int j=num_layers-1; j>=0; j--) {
#pragma omp task depend (in: dep_b[i*num_layers + j]) depend (out: dep_u[i*num_layers + j]) firstprivate(j) shared(D)
{
D.update(j);
}
}
} // End of one iteration
}
} // End of omp parallel
delete [] dep_f;
delete [] dep_b;
delete [] dep_u;
}
void run_omp(const unsigned num_epochs, const unsigned num_threads) {
auto dnns = std::make_unique(NUM_DNNS);
for(auto i=0u; i