<div dir="ltr"><div dir="ltr"><div dir="ltr">Hi,<div><br></div><div>I'm trying openmp offloading to gpu and I'm getting a segfault when trying to run a test code. I followed the instructions explained here <a href="https://www.hahnjo.de/blog/2018/10/08/clang-7.0-openmp-offloading-nvidia.html">https://www.hahnjo.de/blog/2018/10/08/clang-7.0-openmp-offloading-nvidia.html</a>.</div><div><br></div><div>Here is the piece of code I'm trying to run:</div><div><br></div><div><div>#include <malloc.h></div><div>#include <stdio.h></div><div>#include <stdlib.h></div><div> </div><div>int main(int argc, char* argv[])</div><div>{</div><div>    if (argc != 2)</div><div>    {</div><div>        printf("Usage: %s \n", argv[0]);</div><div>        return 0;</div><div>    }</div><div>     </div><div>    int n = atoi(argv[1]);</div><div>     </div><div>    double* x = (double*)malloc(sizeof(double) * n);</div><div>    double* y = (double*)malloc(sizeof(double) * n);</div><div> </div><div>    double idrandmax = 1.0 / RAND_MAX;</div><div>    double a = idrandmax * rand();</div><div>    for (int i = 0; i < n; i++)</div><div>    {</div><div>        x[i] = idrandmax * rand();</div><div>        y[i] = idrandmax * rand();</div><div>    }</div><div>    printf("Here\n\n");</div><div>    #pragma omp target</div><div>    #pragma omp parallel for</div><div>    {</div><div>        for (int i = 0; i < n; i++)</div><div>            y[i] += a * x[i];</div><div>    }</div><div>     </div><div>    double avg = 0.0, min = y[0], max = y[0];</div><div>    for (int i = 0; i < n; i++)</div><div>    {</div><div>        avg += y[i];</div><div>        if (y[i] > max) max = y[i];</div><div>        if (y[i] < min) min = y[i];</div><div>    }</div><div>     </div><div>    printf("min = %f, max = %f, avg = %f\n", min, max, avg / n);</div><div>     </div><div>    free(x);</div><div>    free(y);</div><div> </div><div>    return 0;</div><div>}</div></div><div><br></div><div>I'm compiling the code like this: <span style="color:rgb(0,0,0)">clang </span><span class="gmail-nt" style="color:rgb(0,0,0)">-fopenmp</span><span style="color:rgb(0,0,0)"> </span><span class="gmail-nt" style="color:rgb(0,0,0)">-fopenmp-targets</span><span class="gmail-o" style="color:rgb(0,0,0)">=</span><span style="color:rgb(0,0,0)">nvptx64 </span><span class="gmail-nt" style="color:rgb(0,0,0)">-O2</span><span style="color:rgb(0,0,0)"> example.c</span></div><div><span style="color:rgb(0,0,0)">When I run I get a Segmentation fault immediately.</span></div><div><span style="color:rgb(0,0,0)"><br></span></div><div><span style="color:rgb(0,0,0)">Any thoughts?</span></div><div><span style="color:rgb(0,0,0)"><br></span></div><div><span style="color:rgb(0,0,0)">Thanks!</span></div><div><span style="color:rgb(0,0,0)">Talita</span></div><div><br></div></div></div></div>