bug report [icc version 12.1.3] extern inside openmp block

bug report [icc version 12.1.3] extern inside openmp block

Hello,

Let's we have two files extern.cpp and main.cpp

extern.cpp:

---------------

double e;

--------------

main.cpp

----------------------------

#include <iostream>
using namespace std;

void set()
{
   extern double e;
   e = 10;
}

int main()
{
   set();
#pragma omp parallel for
   for (int i = 0 ; i < 10 ; i++)
     {
        extern double e;
        cout<<e<<endl;
     }
}

-------------------------

after compilation: icc main.cpp extern.cpp -openmp, program print zeros. For some reason e inside loop became equal 0.

Cheers,

Sergey

AnhangGröße
Herunterladen extern.cpp11 Bytes
Herunterladen main.cpp224 Bytes
5 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.

Could you provide some additional information? That is:

- Platform ( OS )
- Version of Intel C++ compiler and Update number
- A complete command line to compile the test

Thank you in advance.

platform - linux (Mageia release 2 (Official) for x86_64)

icc version - Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 12.1.3.293 Build 20120212

compilation command - icc extern.cpp main.cpp -openmp

platform --- Mageia release 2 (Official) for x86_64

icc version ---  Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 12.1.3.293 Build 20120212
Copyright (C) 1985-2012 Intel Corporation.  All rights reserved.

compile --- " icc main.cpp extern.cpp -openmp" 

Greetings,

IMO it is caused by optimization called "constant propagation", that is, when you set "e=0;" the compiler treats it as it is always zero, thus propagating constant. NB that this is compiler-specific, each compiler has its own algorithms for optimization. Since you set the 'e' to '10', I have suspicion that it is bug in ICC. Try to make declaration of "double e;" volatile, i.e. "volatile double e;", to let the compiler know that optimization should not be assumed and performed regarding to variable 'e'. Of course, you will get performance impact, sice compiler will not oprimize volatile variables.

Anyways, it seems to me that it is bug in ICC, and it assumes constant propagation optimization in a bad way.

Could you please test it under ICC 13 (most preferably "update 3" that is current and most recent version)? Maybe it has been fixed since then.

--
With best regards,
VooDooMan
-
If you find my post helpful, please rate it and/or select it as a best answer where applies. Thank you.

Kommentar hinterlassen

Bitte anmelden, um einen Kommentar hinzuzufügen. Sie sind noch nicht Mitglied? Jetzt teilnehmen