-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenMP.cpp
More file actions
69 lines (61 loc) · 1.73 KB
/
OpenMP.cpp
File metadata and controls
69 lines (61 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <fstream>
#include <omp.h>
#include <stdlib.h>
#define R 3
#define LAYERDIM 32
using namespace std;
inline double activationFunction( double x )
{
return 1/(1+exp(-x));
}
double* feedForward(double weigths[9], float bias, double layer[], int lengthLayer)
{
int step = R;
double* nextLayer = new double[lengthLayer/R];
int j = 0;
#pragma omp parallel for
for (int b = 0; b<lengthLayer; b += step) {
float value = 0;
for(int i = 0; i < R; i++) {
value += weigths[b+i]*layer[b+i];
cout << weigths[b+i] << " WEIGHT " << layer[b+i] << " INPUT " << bias << "\n";
}
value += bias;
cout << value << " VALUE\n";
nextLayer[j] = activationFunction(value);
cout << nextLayer[j] << " NEXT LAYER " << j << " \n";
j += 1;
}
return nextLayer;
}
int main(void)
{
double weights[LAYERDIM];
for (int i = 0; i < LAYERDIM; i++){
weights[i] =static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
cout << weights[i] << '\n';
}
double layer[LAYERDIM];
for (int i = 0; i < LAYERDIM; i++){
layer[i] =static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
cout << layer[i] << '\n';
}
float bias = 0.1;
int lengthLayer = LAYERDIM;
int idLayer = 0;
double* val = feedForward(weights, bias, layer, lengthLayer);
ofstream myfile ("C:/Users/damic/Desktop/example.txt");
if (myfile.is_open())
{
for (int i = 0; i < lengthLayer/R; i++){
myfile << val[i] << "\n";
cout << val[i] << "\n";
}
myfile.close();
}
else printf("UNABLE TO OPEN FILE");
return 0;
}