Execution on Intel® Xeon Phi™ co-processor
We tested the speedups on the Intel® Xeon Phi™ with the following code:
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <assert.h>
5 #include <omp.h>
6 #include <math.h>
7
8 int main(int argc, char *argv[]) {
9 int numthreads;
10 int n;
11
12 assert(argc == 3 && "args: numthreads n");
13 sscanf(argv[1], "%d", &numthreads);
14 sscanf(argv[2], "%d", &n);
15
16 printf("Init...\n");
17 printf("Start (%d threads)...\n", numthreads);
18 printf("%d test cases\n", n);
19
20 int m = 1000000;
21 double ttime = omp_get_wtime();
22
23 int i;
24 double d = 0;
25 #pragma offload target(mic:0)
26 {
27 #pragma omp parallel for private (i) schedule(static) num_threads(numthreads)
28 for(i = 0; i < n; ++i) {
29 for(int j = 0; j < m; ++j) {
30 d = sin(d) + 0.1 + j;
31 d = pow(0.2, d)*j;
32 }
33 }
34 }
35 double time = omp_get_wtime() - ttime;
36 fprintf(stderr, "%d %d %.6f\n", n, numthreads, time);
37 printf("time: %.6f s\n", time);
38 printf("Done d = %.6lf.\n", d);
39
40 return 0;
41 }
The code essentially distributes a problem of size $n\cdot m$ among numthreads
cores,
We tested the time of execution for $n$ from the set $\{1, 10, 20, 50, 100, 200, 500, 1000\}$
and numthreads
from $1$ to $350$. The plots of exectuion times and performance speeups are shown below.
The code was compiled using:
icc -openmp -O3 -qopt-report=2 -qopt-report-phase=vec -o test test.cpp
without warnings or errors. Then, in order to offload to Intel Phi, user must be logged in as root:
sudo su
To run correctly, intel compiler and runtime variables must be sourced:
source /opt/intel/bin/compilervars.sh intel64
Finally, the code was tested using the following command, where test
is the name of the compiled executable:
for n in 1 10 20 50 100 200 500 1000; do for nt in {1..350}; echo $nt $n; ./test $nt $n 2>> speedups.txt; done; done