Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Daisuke_S_
Beginner
58 Views

OpenMP bug with nested parallel for

Compiler version: icc 17.0.1 20161013

OS version: macOS Sierra 10.12.1

The code below generates wrong output.

#include <stdio.h>

int main(void)
{
    #pragma omp parallel for
    for (int i = 1; i < 2; i++) {
        #pragma omp parallel for
        for (int j = 0; j < 1; j++) {
            printf("%d\n", i);
        }
    }
}

Expected result: 1

Actual result: 0

0 Kudos
9 Replies
Igor_V_Intel
Employee
58 Views

The loop itself is quite odd. You are creating a team of parallel threads to execute only 1 iteration, and later creating for each of the original threads another team, i.e. a team of teams, just to execute one more iteration. This code is useless.

By the way, I was not able to reproduce the problem with 0 output. How did you compile this test?

In addition, you may use a collapse clause to parallelize nested loops. However, in this example it doesn't make sense to use OpenMP.

Daisuke_S_
Beginner
58 Views

I compiled this with `icc -qopenmp foo.c`.

I know this code is not useful, but this is at least an legal OpenMP code. I inteded to make the code as minimal as possible, while it can reproduce the problem. The problem is that the compiler does not seems to make the variable i "shared" for inner parallel for region. The variable i should be implicitly shared according to the OpenMP specification.

 

jimdempseyatthecove
Black Belt
58 Views

Igor,

FYI Reproducers are typically pointless. The structure of the reproducer in #1 is perfectly valid (regardless of being useless).

Daisuke,

Can you debug the reproducer by placing a break at the printf. Try not to change the compiler switches. Then at the break point, use Disassembly, list the entire code of main, then use the {...}/code button to paste the text in to this forum code window (use plain text format).

If you do change options, assure that running without debugging reproduces your error.

Jim Dempsey

 

Daisuke_S_
Beginner
58 Views

I compiled the code with `icc -qopenmp -g foo.c`. I confirmed the problem is still reproduced with -g option (and without debugging).

Here is the result of disassemble, using LLDB:

a.out`main:
    0x100000978 <+0>:    pushq  %rbp
    0x100000979 <+1>:    movq   %rsp, %rbp
    0x10000097c <+4>:    subq   $0xc0, %rsp
    0x100000983 <+11>:   movq   %r15, -0x8(%rbp)
    0x100000987 <+15>:   movq   %r14, -0x10(%rbp)
    0x10000098b <+19>:   movq   %r13, -0x18(%rbp)
    0x10000098f <+23>:   movq   %r12, -0x20(%rbp)
    0x100000993 <+27>:   movq   %rbx, -0x28(%rbp)
    0x100000997 <+31>:   leaq   0x6d6(%rip), %rax         ; .2.1_2_kmpc_loc_struct_pack.1
    0x10000099e <+38>:   movl   $0x0, %edx
    0x1000009a3 <+43>:   movq   %rax, %rdi
    0x1000009a6 <+46>:   movq   %rdx, %rsi
    0x1000009a9 <+49>:   movl   $0x0, %eax
    0x1000009ae <+54>:   callq  0x100000ea4               ; symbol stub for: __kmpc_begin
    0x1000009b3 <+59>:   leaq   0x6e6(%rip), %rax         ; .2.1_2_kmpc_loc_struct_pack.12
    0x1000009ba <+66>:   movq   %rax, %rdi
    0x1000009bd <+69>:   callq  0x100000ec8               ; symbol stub for: __kmpc_global_thread_num
    0x1000009c2 <+74>:   movl   %eax, -0x88(%rbp)
    0x1000009c8 <+80>:   leaq   0x761(%rip), %rax         ; .2.1_2_kmpc_loc_struct_pack.49
    0x1000009cf <+87>:   movq   %rax, %rdi
    0x1000009d2 <+90>:   movl   $0x0, %eax
    0x1000009d7 <+95>:   callq  0x100000ece               ; symbol stub for: __kmpc_ok_to_fork
    0x1000009dc <+100>:  movl   %eax, -0x80(%rbp)
    0x1000009df <+103>:  movl   -0x80(%rbp), %eax
    0x1000009e2 <+106>:  testl  %eax, %eax
    0x1000009e4 <+108>:  jne    0x100000a39               ; <+193> at foo.c:5
    0x1000009e6 <+110>:  leaq   0x743(%rip), %rax         ; .2.1_2_kmpc_loc_struct_pack.49
    0x1000009ed <+117>:  movl   -0x88(%rbp), %edx
    0x1000009f3 <+123>:  movq   %rax, %rdi
    0x1000009f6 <+126>:  movl   %edx, %esi
    0x1000009f8 <+128>:  movl   $0x0, %eax
    0x1000009fd <+133>:  callq  0x100000ed4               ; symbol stub for: __kmpc_serialized_parallel
    0x100000a02 <+138>:  leaq   -0x88(%rbp), %rax
    0x100000a09 <+145>:  leaq   0x738(%rip), %rdx         ; __kmpv_zero_main_0
    0x100000a10 <+152>:  movq   %rax, %rdi
    0x100000a13 <+155>:  movq   %rdx, %rsi
    0x100000a16 <+158>:  callq  0x100000b9e               ; <+550> at foo.c:5
    0x100000a1b <+163>:  leaq   0x70e(%rip), %rax         ; .2.1_2_kmpc_loc_struct_pack.49
    0x100000a22 <+170>:  movl   -0x88(%rbp), %edx
    0x100000a28 <+176>:  movq   %rax, %rdi
    0x100000a2b <+179>:  movl   %edx, %esi
    0x100000a2d <+181>:  movl   $0x0, %eax
    0x100000a32 <+186>:  callq  0x100000eb0               ; symbol stub for: __kmpc_end_serialized_parallel
    0x100000a37 <+191>:  jmp    0x100000a5f               ; <+231> at foo.c:12
    0x100000a39 <+193>:  leaq   0x6f0(%rip), %rax         ; .2.1_2_kmpc_loc_struct_pack.49
    0x100000a40 <+200>:  movl   $0x0, %edx
    0x100000a45 <+205>:  leaq   0x152(%rip), %rcx         ; <+550> at foo.c:5
    0x100000a4c <+212>:  movq   %rax, %rdi
    0x100000a4f <+215>:  movq   %rdx, %rsi
    0x100000a52 <+218>:  movq   %rcx, %rdx
    0x100000a55 <+221>:  movl   $0x0, %eax
    0x100000a5a <+226>:  callq  0x100000ec2               ; symbol stub for: __kmpc_fork_call
    0x100000a5f <+231>:  leaq   0x66a(%rip), %rax         ; .2.1_2_kmpc_loc_struct_pack.20
    0x100000a66 <+238>:  movq   %rax, %rdi
    0x100000a69 <+241>:  movl   $0x0, %eax
    0x100000a6e <+246>:  callq  0x100000eaa               ; symbol stub for: __kmpc_end
    0x100000a73 <+251>:  movl   $0x0, %eax
    0x100000a78 <+256>:  movq   -0x28(%rbp), %rbx
    0x100000a7c <+260>:  movq   -0x20(%rbp), %r12
    0x100000a80 <+264>:  movq   -0x18(%rbp), %r13
    0x100000a84 <+268>:  movq   -0x10(%rbp), %r14
    0x100000a88 <+272>:  movq   -0x8(%rbp), %r15
    0x100000a8c <+276>:  leave
    0x100000a8d <+277>:  retq
    0x100000a8e <+278>:  movl   $0x1, -0x9c(%rbp)
    0x100000a98 <+288>:  movl   -0xb4(%rbp), %eax
    0x100000a9e <+294>:  movl   $0x1, %edx
    0x100000aa3 <+299>:  subl   %edx, %eax
    0x100000aa5 <+301>:  movl   %eax, -0x98(%rbp)
    0x100000aab <+307>:  movl   -0xb4(%rbp), %eax
    0x100000ab1 <+313>:  movl   $0x1, %edx
    0x100000ab6 <+318>:  subl   %edx, %eax
    0x100000ab8 <+320>:  movl   %eax, -0x94(%rbp)
    0x100000abe <+326>:  movl   $0x0, -0x90(%rbp)
    0x100000ac8 <+336>:  movl   $0x1, -0x8c(%rbp)
    0x100000ad2 <+346>:  addq   $-0x20, %rsp
    0x100000ad6 <+350>:  leaq   0x653(%rip), %rax         ; .2.1_2_kmpc_loc_struct_pack.49
    0x100000add <+357>:  movl   $0x22, %edx
    0x100000ae2 <+362>:  leaq   -0x90(%rbp), %rcx
    0x100000ae9 <+369>:  leaq   -0x9c(%rbp), %rbx
    0x100000af0 <+376>:  leaq   -0x98(%rbp), %rsi
    0x100000af7 <+383>:  leaq   -0x8c(%rbp), %rdi
    0x100000afe <+390>:  movq   %rdi, (%rsp)
    0x100000b02 <+394>:  movl   $0x1, 0x8(%rsp)
    0x100000b0a <+402>:  movl   $0x1, 0x10(%rsp)
    0x100000b12 <+410>:  movq   %rax, %rdi
    0x100000b15 <+413>:  movl   -0x74(%rbp), %eax
    0x100000b18 <+416>:  movq   %rsi, -0x38(%rbp)
    0x100000b1c <+420>:  movl   %eax, %esi
    0x100000b1e <+422>:  movq   %rbx, %r8
    0x100000b21 <+425>:  movq   -0x38(%rbp), %rax
    0x100000b25 <+429>:  movq   %rax, %r9
    0x100000b28 <+432>:  callq  0x100000ebc               ; symbol stub for: __kmpc_for_static_init_4
    0x100000b2d <+437>:  addq   $0x20, %rsp
    0x100000b31 <+441>:  movl   -0x9c(%rbp), %eax
    0x100000b37 <+447>:  movl   %eax, -0x7c(%rbp)
    0x100000b3a <+450>:  movl   -0x98(%rbp), %edx
    0x100000b40 <+456>:  movl   %edx, -0x78(%rbp)
    0x100000b43 <+459>:  movl   %edx, -0x78(%rbp)
    0x100000b46 <+462>:  movl   -0x94(%rbp), %edx
    0x100000b4c <+468>:  cmpl   %edx, %eax
    0x100000b4e <+470>:  jg     0x100000b6f               ; <+503> at foo.c:5
    0x100000b50 <+472>:  movl   -0x94(%rbp), %eax
    0x100000b56 <+478>:  movl   -0x78(%rbp), %edx
    0x100000b59 <+481>:  cmpl   %eax, %edx
    0x100000b5b <+483>:  jle    0x100000bf8               ; <+640> at foo.c:5
    0x100000b61 <+489>:  movl   -0x94(%rbp), %eax
    0x100000b67 <+495>:  movl   %eax, -0x78(%rbp)
    0x100000b6a <+498>:  jmp    0x100000bf8               ; <+640> at foo.c:5
    0x100000b6f <+503>:  leaq   0x5ba(%rip), %rax         ; .2.1_2_kmpc_loc_struct_pack.49
    0x100000b76 <+510>:  movq   %rax, %rdi
    0x100000b79 <+513>:  movl   -0x74(%rbp), %eax
    0x100000b7c <+516>:  movl   %eax, %esi
    0x100000b7e <+518>:  callq  0x100000eb6               ; symbol stub for: __kmpc_for_static_fini
    0x100000b83 <+523>:  movl   $0x0, %eax
    0x100000b88 <+528>:  movq   -0x28(%rbp), %rbx
    0x100000b8c <+532>:  movq   -0x20(%rbp), %r12
    0x100000b90 <+536>:  movq   -0x18(%rbp), %r13
    0x100000b94 <+540>:  movq   -0x10(%rbp), %r14
    0x100000b98 <+544>:  movq   -0x8(%rbp), %r15
    0x100000b9c <+548>:  leave
    0x100000b9d <+549>:  retq
    0x100000b9e <+550>:  pushq  %rbp
    0x100000b9f <+551>:  movq   %rsp, %rbp
    0x100000ba2 <+554>:  subq   $0xc0, %rsp
    0x100000ba9 <+561>:  movq   %r15, -0x8(%rbp)
    0x100000bad <+565>:  movq   %r14, -0x10(%rbp)
    0x100000bb1 <+569>:  movq   %r13, -0x18(%rbp)
    0x100000bb5 <+573>:  movq   %r12, -0x20(%rbp)
    0x100000bb9 <+577>:  movq   %rbx, -0x28(%rbp)
    0x100000bbd <+581>:  movq   %rdi, -0x48(%rbp)
    0x100000bc1 <+585>:  movq   %rsi, -0x40(%rbp)
    0x100000bc5 <+589>:  movq   -0x48(%rbp), %rax
    0x100000bc9 <+593>:  movl   (%rax), %eax
    0x100000bcb <+595>:  movl   %eax, -0x74(%rbp)
    0x100000bce <+598>:  movl   $0x1, -0xb8(%rbp)
    0x100000bd8 <+608>:  movl   $0x2, -0xb4(%rbp)
    0x100000be2 <+618>:  movl   -0xb8(%rbp), %eax
    0x100000be8 <+624>:  movl   -0xb4(%rbp), %edx
    0x100000bee <+630>:  cmpl   %edx, %eax
    0x100000bf0 <+632>:  jl     0x100000a8e               ; <+278> at foo.c:5
    0x100000bf6 <+638>:  jmp    0x100000b83               ; <+523> at foo.c:5
    0x100000bf8 <+640>:  movl   -0x78(%rbp), %eax
    0x100000bfb <+643>:  movl   -0x7c(%rbp), %edx
    0x100000bfe <+646>:  movl   %edx, -0xb8(%rbp)
    0x100000c04 <+652>:  movl   -0xb8(%rbp), %edx
    0x100000c0a <+658>:  cmpl   %eax, %edx
    0x100000c0c <+660>:  jg     0x100000b6f               ; <+503> at foo.c:5
    0x100000c12 <+666>:  leaq   0x4e7(%rip), %rax         ; .2.1_2_kmpc_loc_struct_pack.28
    0x100000c19 <+673>:  movq   %rax, %rdi
    0x100000c1c <+676>:  movl   $0x0, %eax
    0x100000c21 <+681>:  callq  0x100000ece               ; symbol stub for: __kmpc_ok_to_fork
    0x100000c26 <+686>:  movl   %eax, -0x70(%rbp)
    0x100000c29 <+689>:  movl   -0x70(%rbp), %eax
    0x100000c2c <+692>:  testl  %eax, %eax
    0x100000c2e <+694>:  jne    0x100000c84               ; <+780> at foo.c:7
    0x100000c30 <+696>:  leaq   0x4c9(%rip), %rax         ; .2.1_2_kmpc_loc_struct_pack.28
    0x100000c37 <+703>:  movq   %rax, %rdi
    0x100000c3a <+706>:  movl   -0x74(%rbp), %eax
    0x100000c3d <+709>:  movl   %eax, %esi
    0x100000c3f <+711>:  movl   $0x0, %eax
    0x100000c44 <+716>:  callq  0x100000ed4               ; symbol stub for: __kmpc_serialized_parallel
    0x100000c49 <+721>:  movq   -0x48(%rbp), %rax
    0x100000c4d <+725>:  leaq   0x4f8(%rip), %rdx         ; __kmpv_zero_main_1
    0x100000c54 <+732>:  leaq   -0xb8(%rbp), %rcx
    0x100000c5b <+739>:  movq   %rax, %rdi
    0x100000c5e <+742>:  movq   %rdx, %rsi
    0x100000c61 <+745>:  movq   %rcx, %rdx
    0x100000c64 <+748>:  callq  0x100000dea               ; <+1138> at foo.c:7
    0x100000c69 <+753>:  leaq   0x490(%rip), %rax         ; .2.1_2_kmpc_loc_struct_pack.28
    0x100000c70 <+760>:  movq   %rax, %rdi
    0x100000c73 <+763>:  movl   -0x74(%rbp), %eax
    0x100000c76 <+766>:  movl   %eax, %esi
    0x100000c78 <+768>:  movl   $0x0, %eax
    0x100000c7d <+773>:  callq  0x100000eb0               ; symbol stub for: __kmpc_end_serialized_parallel
    0x100000c82 <+778>:  jmp    0x100000cb3               ; <+827> at foo.c:7
    0x100000c84 <+780>:  leaq   0x475(%rip), %rax         ; .2.1_2_kmpc_loc_struct_pack.28
    0x100000c8b <+787>:  movl   $0x1, %edx
    0x100000c90 <+792>:  leaq   0x153(%rip), %rcx         ; <+1138> at foo.c:7
    0x100000c97 <+799>:  leaq   -0xb8(%rbp), %rbx
    0x100000c9e <+806>:  movq   %rax, %rdi
    0x100000ca1 <+809>:  movl   %edx, %esi
    0x100000ca3 <+811>:  movq   %rcx, %rdx
    0x100000ca6 <+814>:  movq   %rbx, %rcx
    0x100000ca9 <+817>:  movl   $0x0, %eax
    0x100000cae <+822>:  callq  0x100000ec2               ; symbol stub for: __kmpc_fork_call
    0x100000cb3 <+827>:  movl   -0x78(%rbp), %eax
    0x100000cb6 <+830>:  movl   $0x1, %edx
    0x100000cbb <+835>:  addl   -0xb8(%rbp), %edx
    0x100000cc1 <+841>:  movl   %edx, -0xb8(%rbp)
    0x100000cc7 <+847>:  movl   -0xb8(%rbp), %edx
    0x100000ccd <+853>:  cmpl   %eax, %edx
    0x100000ccf <+855>:  jle    0x100000c12               ; <+666> at foo.c:7
    0x100000cd5 <+861>:  jmp    0x100000b6f               ; <+503> at foo.c:5
    0x100000cda <+866>:  movl   $0x0, -0xb0(%rbp)
    0x100000ce4 <+876>:  movl   -0xbc(%rbp), %eax
    0x100000cea <+882>:  movl   $0x1, %edx
    0x100000cef <+887>:  subl   %edx, %eax
    0x100000cf1 <+889>:  movl   %eax, -0xac(%rbp)
    0x100000cf7 <+895>:  movl   -0xbc(%rbp), %eax
    0x100000cfd <+901>:  movl   $0x1, %edx
    0x100000d02 <+906>:  subl   %edx, %eax
    0x100000d04 <+908>:  movl   %eax, -0xa8(%rbp)
    0x100000d0a <+914>:  movl   $0x0, -0xa4(%rbp)
    0x100000d14 <+924>:  movl   $0x1, -0xa0(%rbp)
    0x100000d1e <+934>:  addq   $-0x20, %rsp
    0x100000d22 <+938>:  leaq   0x3d7(%rip), %rax         ; .2.1_2_kmpc_loc_struct_pack.28
    0x100000d29 <+945>:  movl   $0x22, %edx
    0x100000d2e <+950>:  leaq   -0xa4(%rbp), %rcx
    0x100000d35 <+957>:  leaq   -0xb0(%rbp), %rbx
    0x100000d3c <+964>:  leaq   -0xac(%rbp), %rsi
    0x100000d43 <+971>:  leaq   -0xa0(%rbp), %rdi
    0x100000d4a <+978>:  movq   %rdi, (%rsp)
    0x100000d4e <+982>:  movl   $0x1, 0x8(%rsp)
    0x100000d56 <+990>:  movl   $0x1, 0x10(%rsp)
    0x100000d5e <+998>:  movq   %rax, %rdi
    0x100000d61 <+1001>: movl   -0x64(%rbp), %eax
    0x100000d64 <+1004>: movq   %rsi, -0x30(%rbp)
    0x100000d68 <+1008>: movl   %eax, %esi
    0x100000d6a <+1010>: movq   %rbx, %r8
    0x100000d6d <+1013>: movq   -0x30(%rbp), %rax
    0x100000d71 <+1017>: movq   %rax, %r9
    0x100000d74 <+1020>: callq  0x100000ebc               ; symbol stub for: __kmpc_for_static_init_4
    0x100000d79 <+1025>: addq   $0x20, %rsp
    0x100000d7d <+1029>: movl   -0xb0(%rbp), %eax
    0x100000d83 <+1035>: movl   %eax, -0x6c(%rbp)
    0x100000d86 <+1038>: movl   -0xac(%rbp), %edx
    0x100000d8c <+1044>: movl   %edx, -0x68(%rbp)
    0x100000d8f <+1047>: movl   %edx, -0x68(%rbp)
    0x100000d92 <+1050>: movl   -0xa8(%rbp), %edx
    0x100000d98 <+1056>: cmpl   %edx, %eax
    0x100000d9a <+1058>: jg     0x100000dbb               ; <+1091> at foo.c:7
    0x100000d9c <+1060>: movl   -0xa8(%rbp), %eax
    0x100000da2 <+1066>: movl   -0x68(%rbp), %edx
    0x100000da5 <+1069>: cmpl   %eax, %edx
    0x100000da7 <+1071>: jle    0x100000e48               ; <+1232> at foo.c:7
    0x100000dad <+1077>: movl   -0xa8(%rbp), %eax
    0x100000db3 <+1083>: movl   %eax, -0x68(%rbp)
    0x100000db6 <+1086>: jmp    0x100000e48               ; <+1232> at foo.c:7
    0x100000dbb <+1091>: leaq   0x33e(%rip), %rax         ; .2.1_2_kmpc_loc_struct_pack.28
    0x100000dc2 <+1098>: movq   %rax, %rdi
    0x100000dc5 <+1101>: movl   -0x64(%rbp), %eax
    0x100000dc8 <+1104>: movl   %eax, %esi
    0x100000dca <+1106>: callq  0x100000eb6               ; symbol stub for: __kmpc_for_static_fini
    0x100000dcf <+1111>: movl   $0x0, %eax
    0x100000dd4 <+1116>: movq   -0x28(%rbp), %rbx
    0x100000dd8 <+1120>: movq   -0x20(%rbp), %r12
    0x100000ddc <+1124>: movq   -0x18(%rbp), %r13
    0x100000de0 <+1128>: movq   -0x10(%rbp), %r14
    0x100000de4 <+1132>: movq   -0x8(%rbp), %r15
    0x100000de8 <+1136>: leave
    0x100000de9 <+1137>: retq
    0x100000dea <+1138>: pushq  %rbp
    0x100000deb <+1139>: movq   %rsp, %rbp
    0x100000dee <+1142>: subq   $0xc0, %rsp
    0x100000df5 <+1149>: movq   %r15, -0x8(%rbp)
    0x100000df9 <+1153>: movq   %r14, -0x10(%rbp)
    0x100000dfd <+1157>: movq   %r13, -0x18(%rbp)
    0x100000e01 <+1161>: movq   %r12, -0x20(%rbp)
    0x100000e05 <+1165>: movq   %rbx, -0x28(%rbp)
    0x100000e09 <+1169>: movq   %rdi, -0x60(%rbp)
    0x100000e0d <+1173>: movq   %rsi, -0x58(%rbp)
    0x100000e11 <+1177>: movq   %rdx, -0x50(%rbp)
    0x100000e15 <+1181>: movq   -0x60(%rbp), %rax
    0x100000e19 <+1185>: movl   (%rax), %eax
    0x100000e1b <+1187>: movl   %eax, -0x64(%rbp)
    0x100000e1e <+1190>: movl   $0x0, -0xc0(%rbp)
    0x100000e28 <+1200>: movl   $0x1, -0xbc(%rbp)
    0x100000e32 <+1210>: movl   -0xc0(%rbp), %eax
    0x100000e38 <+1216>: movl   -0xbc(%rbp), %edx
    0x100000e3e <+1222>: cmpl   %edx, %eax
    0x100000e40 <+1224>: jl     0x100000cda               ; <+866> at foo.c:7
    0x100000e46 <+1230>: jmp    0x100000dcf               ; <+1111> at foo.c:7
    0x100000e48 <+1232>: movl   -0x68(%rbp), %eax
    0x100000e4b <+1235>: movl   -0x6c(%rbp), %edx
    0x100000e4e <+1238>: movl   %edx, -0xc0(%rbp)
    0x100000e54 <+1244>: movl   -0xc0(%rbp), %edx
    0x100000e5a <+1250>: cmpl   %eax, %edx
    0x100000e5c <+1252>: jle    0x100000e85               ; <+1293> at foo.c:9
    0x100000e5e <+1254>: jmp    0x100000dbb               ; <+1091> at foo.c:7
    0x100000e63 <+1259>: movl   -0x68(%rbp), %eax
    0x100000e66 <+1262>: movl   $0x1, %edx
    0x100000e6b <+1267>: addl   -0xc0(%rbp), %edx
    0x100000e71 <+1273>: movl   %edx, -0xc0(%rbp)
    0x100000e77 <+1279>: movl   -0xc0(%rbp), %edx
    0x100000e7d <+1285>: cmpl   %eax, %edx
    0x100000e7f <+1287>: jg     0x100000dbb               ; <+1091> at foo.c:7
->  0x100000e85 <+1293>: leaq   0xc8(%rip), %rax
    0x100000e8c <+1300>: movl   -0x84(%rbp), %edx
    0x100000e92 <+1306>: movq   %rax, %rdi
    0x100000e95 <+1309>: movl   %edx, %esi
    0x100000e97 <+1311>: movl   $0x0, %eax
    0x100000e9c <+1316>: callq  0x100000eda               ; symbol stub for: printf
    0x100000ea1 <+1321>: jmp    0x100000e63               ; <+1259> at foo.c:8
    0x100000ea3 <+1323>: nop

 

Igor_V_Intel
Employee
58 Views

Yes, the code is legal. Thanks for creating a small reproducer - I will try on Mac system as well (no issue on Windows and Linux).

Igor_V_Intel
Employee
58 Views

Could you please let me know the number of threads you set while running this example? I still not able to reproduce it on Mac OS as well.

Daisuke_S_
Beginner
58 Views

The number of threads is 4, as my environment has 4 logical cores. But even when OMP_NUM_THREADS is set to another value, I get the same result.

Daisuke_S_
Beginner
58 Views

Let me make a correction. The compilation command was actually `icc -qopenmp -std=c11 foo.c` (I forgot that `icc` is an alias for `icc -std=c11 in my environment). The compilation fails without specifying c99 or above.

The problem seems to occur only when i is declared in initialization part of the for statement. So if you modified the reproducer like this, this is why you couldn't reproduce it.

Sorry for incomplete information.

#include <stdio.h>

int main(void)
{
    int i;
    #pragma omp parallel for
    for (i = 1; i < 2; i++) {
        int j;
        #pragma omp parallel for
        for (j = 0; j < 1; j++) {
            printf("%d\n", i);
        }
    }
}
Igor_V_Intel
Employee
58 Views

Thanks. Now I can reproduce the problem. It doesn't fail if icpc is used, so, something with c99. I escalated this to developers (DPD200416367);

Reply