-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.cpp
More file actions
31 lines (30 loc) · 766 Bytes
/
vector.cpp
File metadata and controls
31 lines (30 loc) · 766 Bytes
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
#include "simple-multithreader.h"
#include <assert.h>
int user_main(int argc, char** argv)
{
// printf("Hello World\n");
// intialize problem size
int numThread = argc>1 ? atoi(argv[1]) : 2;
int size = argc>2 ? atoi(argv[2]) : 48000000;
// allocate vectors
int* A = new int[size];
int* B = new int[size];
int* C = new int[size];
// initialize the vectors
std::fill(A, A+size, 1);
std::fill(B, B+size, 1);
std::fill(C, C+size, 0);
// start the parallel addition of two vectors
parallel_for(0, size, [&](int i)
{
C[i] = A[i] + B[i];
}, numThread);
// verify the result vector
for(int i=0; i<size; i++) assert(C[i] == 2);
printf("Test Success\n");
// cleanup memory
delete[] A;
delete[] B;
delete[] C;
return 0;
}