<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: OpenMP offload: Using global variable with a library in Intel® oneAPI DPC++/C++ Compiler</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/OpenMP-offload-Using-global-variable-with-a-library/m-p/1415182#M2523</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;Santosh&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you very much for your quick response.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I am looking forward to hearing from you regarding this compiler issue.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Christos&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Sep 2022 07:01:05 GMT</pubDate>
    <dc:creator>Christos_Kotsalos</dc:creator>
    <dc:date>2022-09-16T07:01:05Z</dc:date>
    <item>
      <title>OpenMP offload: Using global variable with a library</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/OpenMP-offload-Using-global-variable-with-a-library/m-p/1414168#M2503</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have two questions regarding the usage of global variables with OpenMP offload:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;1.&lt;/STRONG&gt; When I have global variable usage in the code from which I create a library then I get a runtime error. Here is a simple reproducer showing the issue:&lt;/P&gt;
&lt;P&gt;-&amp;gt;&amp;nbsp;&lt;SPAN&gt;qsub -I -l nodes=1:gpu:ppn=2 -d . (Intel DevCloud)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;$ cat test.sh&lt;/P&gt;
&lt;LI-CODE lang="bash"&gt;export OMP_TARGET_OFFLOAD=MANDATORY

CXX=icpx
CXXFLAGS="-qopenmp -fopenmp-targets=spir64"
${CXX} ${CXXFLAGS} -c test.cpp
ar cq libtest.a test.o
${CXX} ${CXXFLAGS} -o test1_ main.cpp -L. -ltest
${CXX} ${CXXFLAGS} -o test2_ main.cpp test.o

echo "*****&amp;gt;intel"
if [ -f test1_ ] ; then ./test1_; echo $?; fi
if [ -f test2_ ] ; then ./test2_; echo $?; fi
rm test*_ *.o *.a
echo "*****&amp;lt;"&lt;/LI-CODE&gt;
&lt;P&gt;$ cat test.cpp&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;#pragma omp declare target
int y;
#pragma omp end declare target

int test() {
  y = 24;
  #pragma omp target update to(y)
  y = 42;

  int x;
  #pragma omp target map(from:x)
  {
    x = y;
  }
  return x;
}&lt;/LI-CODE&gt;
&lt;P&gt;$ cat main.cpp&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;extern int test();

int main() {
  return test();
}&lt;/LI-CODE&gt;
&lt;P&gt;Running the ./test2_ works as expected as I am not using static library but the ./test1_ fails with an error shown below:&lt;/P&gt;
&lt;LI-CODE lang="bash"&gt;LEVEL0 error: Failed to invoke deleted kernel.
Libomptarget error: Executing target region abort target.
Libomptarget error: Run with
Libomptarget error: LIBOMPTARGET_DEBUG=1 to display basic debug information.
Libomptarget error: LIBOMPTARGET_DEBUG=2 to display calls to the compute runtime.
Libomptarget error: LIBOMPTARGET_INFO=4 to dump host-target pointer mappings.
Libomptarget error: Source location information not present. Compile with -g or -gline-tables-only.
Libomptarget fatal error 1: failure of target construct while offloading is mandatory
Aborted
134&lt;/LI-CODE&gt;
&lt;P&gt;FYI, the correct output is 24 (check ./test2_).&lt;/P&gt;
&lt;P&gt;Is this expected behaviour? Is there any workaround? I have tested this with PGI/NVHPC compiler and it works there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;2.&lt;/STRONG&gt; The second scenario is similar but now I am trying to use a global variable from the library into the offload region in main.cpp i.e. modified main.cpp looks as:&lt;/P&gt;
&lt;P&gt;$ cat main.cpp&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;extern int test();

#include &amp;lt;cstdio&amp;gt;

#pragma omp declare target
extern int y;
#pragma omp end declare target

int main() {
  #pragma omp target teams distribute parallel for
  for(int i=0; i&amp;lt;5; i++) {
    printf("--&amp;gt; %d \n", y + i);
  }
  return test();
}&lt;/LI-CODE&gt;
&lt;P&gt;While it compiles for both tests, test2_ fails with the following error:&lt;/P&gt;
&lt;LI-CODE lang="bash"&gt;if [ -f test1_ ] ; then ./test1_; echo $?; fi
--&amp;gt; 0
--&amp;gt; 1
--&amp;gt; 2
--&amp;gt; 3
--&amp;gt; 4
LEVEL0 error: Failed to invoke deleted kernel.
Libomptarget error: Executing target region abort target.
Libomptarget error: Run with
Libomptarget error: LIBOMPTARGET_DEBUG=1 to display basic debug information.
Libomptarget error: LIBOMPTARGET_DEBUG=2 to display calls to the compute runtime.
Libomptarget error: LIBOMPTARGET_INFO=4 to dump host-target pointer mappings.
unknown:11:11: Libomptarget fatal error 1: failure of target construct while offloading is mandatory
Aborted
134&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any feedback would be really helpful and appreciated.&lt;/P&gt;
&lt;P&gt;Thank you very much.&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;Christos&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 11:38:50 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/OpenMP-offload-Using-global-variable-with-a-library/m-p/1414168#M2503</guid>
      <dc:creator>Christos_Kotsalos</dc:creator>
      <dc:date>2022-09-12T11:38:50Z</dc:date>
    </item>
    <item>
      <title>Re:OpenMP offload: Using global variable with a library</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/OpenMP-offload-Using-global-variable-with-a-library/m-p/1414939#M2514</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thank you for posting in the Intel forums.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thanks for providing the sample reproducer code along with the steps to reproduce your issue. We were able to reproduce your issue on Intel DevCloud using the ICPX compiler. We are working on your issue and we will get back to you soon.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; Regards,&lt;/P&gt;&lt;P&gt;Santosh&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 15 Sep 2022 10:32:16 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/OpenMP-offload-Using-global-variable-with-a-library/m-p/1414939#M2514</guid>
      <dc:creator>SantoshY_Intel</dc:creator>
      <dc:date>2022-09-15T10:32:16Z</dc:date>
    </item>
    <item>
      <title>Re: OpenMP offload: Using global variable with a library</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/OpenMP-offload-Using-global-variable-with-a-library/m-p/1415182#M2523</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;Santosh&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you very much for your quick response.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I am looking forward to hearing from you regarding this compiler issue.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Christos&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 07:01:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/OpenMP-offload-Using-global-variable-with-a-library/m-p/1415182#M2523</guid>
      <dc:creator>Christos_Kotsalos</dc:creator>
      <dc:date>2022-09-16T07:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: OpenMP offload: Using global variable with a library</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/OpenMP-offload-Using-global-variable-with-a-library/m-p/1416161#M2543</link>
      <description>&lt;P&gt;Hi Christos,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We have reported this issue to the concerned development team. Your issue will be fixed in the next future release.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Meanwhile, could you please use the below workaround?&lt;/P&gt;
&lt;P&gt;Use the below command which references the full static library name(libtest.a in this case) instead of -lname(ltest in this case):&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;icx -fiopenmp -fopenmp-targets=spir64 -o test1_ main.cpp -L. libtest.a&lt;/LI-CODE&gt;
&lt;P&gt;We tried this workaround at our end and it is working fine without any errors as shown below.&lt;/P&gt;
&lt;P&gt;$ cat test.sh&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;export OMP_TARGET_OFFLOAD=MANDATORY
CXX=icpx
CXXFLAGS="-qopenmp -fopenmp-targets=spir64"
${CXX} ${CXXFLAGS} -c test.cpp
ar cq libtest.a test.o
#${CXX} ${CXXFLAGS} -o test1_ main.cpp -L. -ltest
${CXX} ${CXXFLAGS} -o test1_ main.cpp -L. libtest.a
${CXX} ${CXXFLAGS} -o test2_ main.cpp test.o

echo "*****&amp;gt;intel"
if [ -f test1_ ] ; then ./test1_; echo $?; fi
if [ -f test2_ ] ; then ./test2_; echo $?; fi

rm test*_ *.o *.a
echo "*****&amp;lt;"&lt;/LI-CODE&gt;
&lt;P&gt;The output for scenario-1 would be:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;u67125@s001-n141:~/offload$ sh test.sh
*****&amp;gt;intel
24
24
*****&amp;lt;
u67125@s001-n141:~/offload$&lt;/LI-CODE&gt;
&lt;P&gt;The output for scenario-2 would be:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;u67125@s001-n141:~/offload$ sh test.sh
*****&amp;gt;intel
--&amp;gt; 0
--&amp;gt; 1
--&amp;gt; 2
--&amp;gt; 3
--&amp;gt; 4
24
--&amp;gt; 0
--&amp;gt; 1
--&amp;gt; 2
--&amp;gt; 3
--&amp;gt; 4
24
*****&amp;lt;
u67125@s001-n141:~/offload$
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; Regards,&lt;/P&gt;
&lt;P&gt;Santosh&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 06:31:27 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/OpenMP-offload-Using-global-variable-with-a-library/m-p/1416161#M2543</guid>
      <dc:creator>SantoshY_Intel</dc:creator>
      <dc:date>2022-09-21T06:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: OpenMP offload: Using global variable with a library</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/OpenMP-offload-Using-global-variable-with-a-library/m-p/1416205#M2544</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;Santosh,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you very much for the workaround and for letting me know about the future release.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;FYI, I have tried the workaround and everything works fine.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you for resolving the issue.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Christos&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 09:28:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/OpenMP-offload-Using-global-variable-with-a-library/m-p/1416205#M2544</guid>
      <dc:creator>Christos_Kotsalos</dc:creator>
      <dc:date>2022-09-21T09:28:56Z</dc:date>
    </item>
    <item>
      <title>Re:OpenMP offload: Using global variable with a library</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/OpenMP-offload-Using-global-variable-with-a-library/m-p/1416210#M2545</link>
      <description>&lt;P&gt;Hi Christos,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thanks for accepting our solution. If you need any additional information, please post a new question as this thread will no longer be monitored by Intel.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; Regards,&lt;/P&gt;&lt;P&gt;Santosh&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Sep 2022 10:06:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/OpenMP-offload-Using-global-variable-with-a-library/m-p/1416210#M2545</guid>
      <dc:creator>SantoshY_Intel</dc:creator>
      <dc:date>2022-09-21T10:06:19Z</dc:date>
    </item>
  </channel>
</rss>

