Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
11 Views

Loop not parallelized in OpenMP depending on the code inside

Hi,
I'm having problems with an OpenMP loop when I put inside an exception. In the code, with the 258 revision of the Intel c++ 12.1 por x64, the loop is parallelized (using VS2010 Debug mode options) depending if try/catch is commented or not. Could anyone reproduce this issue?
Thanks in advance!
#include
#include
#include "omp.h"
using namespace std;
int main(){
omp_set_num_threads(8);
#pragma omp parallel for
for(int i=0; i< 3000; i++){
int asdf=2;
try{
cerr << "Im " << omp_get_thread_num()<<" out of " << omp_get_num_threads()<
} catch (exception& e){
//asdf=0;
continue;
}
}
return 0;
}
0 Kudos
10 Replies
Highlighted
Black Belt
11 Views

Others have recommended making the try and catch clauses same-named critical regions, noting that OpenMP requires the catch to be executed by the same thread as the throw.
Did you turn on openmp-report to see if you could get any comments from the compiler?
0 Kudos
Highlighted
Beginner
11 Views

I think I dont get it, how would it be in the example attached?
Using/Qopenmp-report2 and without the exception catch, the report is:
1>...\main.cpp(7): warning : OpenMP DEFINED LOOP WAS PARALLELIZED.
with the exception, no OpenMP defined loop is reported.
Thanks
0 Kudos
Highlighted
Employee
11 Views

If you remove the continue statement from the catch block the code parallizes. I will investigate further and get back to you.

Thanks,
--mark
0 Kudos
Highlighted
Employee
11 Views

It turned out there is a problem in the compiler preventing parallelization of the loop in the presence of the "continue" statement in the catch block. I filed a report on this issue and will let you know when the issue is resolved.

Thanks,
--mark
0 Kudos
Highlighted
Valued Contributor II
11 Views

Itestedthe codewith Visual Studio 2005 to verify compatibility and I detected another issue.

Microsoft C/C++ compiler ignores acontent of a'catch(...)' or 'catch( exception &e )'blocks if all
optimizations are disabled and the compileroutputs a warning:

Warning C4702: Unreachable code

It doesn't matter what was implemented in the block anda content is simply ignored!

Is it expected or not?
0 Kudos
Highlighted
Employee
11 Views

That warning may be specific to VS2005. I do not get that warning with VS2008 nor with the Intel compiler.

--mark
0 Kudos
Highlighted
Valued Contributor II
11 Views

That warning may be specific to VS2005. I do not get that warning with VS2008 nor with the Intel compiler.

--mark


Hi Mark,

Could you verify that a Warning Level in your project is set to 'Level 4 (/W4)'?I'll also verifythe
codewith VS2008 and VS2010.

Best regards,
Sergey

0 Kudos
Highlighted
Employee
11 Views

Hi Sergey,

Here's what I get:

>cl /W4 -openmp t.cpp -c -EHsc -Od
Microsoft 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.

t.cpp
t.cpp(9) : warning C4189: 'asdf' : local variable is initialized but not referenced
t.cpp(12) : warning C4101: 'e' : unreferenced local variable

d:\NOBACKUP\quadtests\forum\102618>icl /W4 -Qopenmp t.cpp -c -EHsc -Od
Intel C++ Intel 64 Compiler XE for applications running on Intel 64, Version 12.1.2.278 Build 20111128
Copyright (C) 1985-2011 Intel Corporation. All rights reserved.

t.cpp
t.cpp(12): remark #177: handler parameter "e" was declared but never referenced
} catch (exception& e){
^

t.cpp(9): remark #177: variable "asdf" was declared but never referenced
int asdf=2;
^


d:\NOBACKUP\quadtests\forum\102618>

>icl /W4 -Qopenmp t.cpp -c -EHsc -Od
Intel C++ Intel 64 Compiler XE for applications running on Intel 64, Version 12.1.2.278 Build 20111128
Copyright (C) 1985-2011 Intel Corporation. All rights reserved.

t.cpp
t.cpp(12): remark #177: handler parameter "e" was declared but never referenced
} catch (exception& e){
^

t.cpp(9): remark #177: variable "asdf" was declared but never referenced
int asdf=2;
^


Thanks,
--mark

0 Kudos
Highlighted
Valued Contributor II
11 Views

Hi Mark,

Here are results of my verification:

VS2005 Professional - Debug - Warning C4702: unreachable code
- Release - No warning

VS2008 Professional - Debug - Warning C4702: unreachable code
- Release - No warning

VS2008 Express - Debug - Warning C4702: unreachable code
- Release - No warning

VS2010 Express - Debug - Warning C4702: unreachable code
- Release - No warning

As you ca see there is noWarning C4702 for Release configurations andI'm a little bit concerned. Is that a feature or a bug?

Some project settings are as follows: /W4 /Od ( All optimizations disabled ) /GR /openmp

Best regards,
Sergey

0 Kudos
Highlighted
Employee
11 Views

This issue has been resolved in the Intel C++ Compiler version 12.1 part of Intel C++ Composer XE update 10 released on April 25, 2012, available for download from registrationcenter.intel.com .

Thanks,
--mark
0 Kudos