forked from TheFighters/Smith-Waterman
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhasGPU.cpp
More file actions
34 lines (30 loc) · 939 Bytes
/
hasGPU.cpp
File metadata and controls
34 lines (30 loc) · 939 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
32
33
34
//https://lc.llnl.gov/confluence/display/LC/Clang+OpenMP+4.5+with+GPU+support#space-menu-link-content
// Revised a bit
#include <stdio.h>
#include <omp.h>
int main()
{
#pragma omp parallel
{
#pragma omp master
{
int thread_count = omp_get_num_threads();
printf ("Using %d out of max %d threads...\n", thread_count, omp_get_max_threads());
}
}
int runningOnGPU = 0;
printf ("The number of target devices =%d\n", omp_get_num_devices());
/* Test if GPU is available using OpenMP4.5 */
#pragma omp target map(from:runningOnGPU)
{
// This function returns true if currently running on the host device, false otherwise.
if (!omp_is_initial_device())
runningOnGPU = 1;
}
/* If still running on CPU, GPU must not be available */
if (runningOnGPU == 1)
printf("### Able to use the GPU! ### \n");
else
printf("### Unable to use the GPU, using CPU! ###\n");
return 0;
}