-
Notifications
You must be signed in to change notification settings - Fork 5
/
gtest_hw4_testomp.cpp
35 lines (30 loc) · 1.18 KB
/
gtest_hw4_testomp.cpp
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
#include <gtest/gtest.h>
#include <fstream>
#include <omp.h>
#include <cstdio>
#include <cstdlib>
#include <thrust/system/omp/execution_policy.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/for_each.h>
TEST(OMP,NumThreads){
/* Fork a team of threads giving them their own copies of variables */
#pragma omp parallel
{
/* Obtain thread number */
int tid = omp_get_thread_num();
printf("Hello World from thread = %d\n", tid);
/* Only master thread does this */
if (tid == 0)
printf("Number of threads = %d\n", omp_get_num_threads());
EXPECT_NE(omp_get_num_threads(), 1) << "Only one thread, not running in parallel environment";
} /* All threads join master thread and disband */
}
TEST(OMP, Thrust){
auto printer = [](int i) {
printf("Hello on element %2d from thread %2d\n", i, omp_get_thread_num());
EXPECT_NE(omp_get_num_threads(), 1) << "Only one thread, not running in parallel environment";
};
using enumerator = thrust::counting_iterator<int>;
thrust::for_each(thrust::omp::par, enumerator(0), enumerator(100), printer);
EXPECT_EQ(omp_get_num_threads(), 1) << "More theads than expected"; //number of threads is one
}