Quantcast
Channel: Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1616

OpenMP code works on 11.1.056 but don't on 14.0.3

$
0
0

Hi guys!

   I have a simple code that depends on OpenMP locks like this.

#include <stdio.h>
#include <unistd.h>
#include <stdarg.h>
#include <sys/wait.h>
#include <omp.h>

static omp_lock_t _log_omp_lock;
static volatile int _log_omp_lock_initialized = 0;

static void _ensure_log_omp_lock_initialized()
{
        if( _log_omp_lock_initialized ) return;

#pragma omp critical (_log_lock_init_critical_name)
    {
        if( ! _log_omp_lock_initialized ) {
            omp_init_lock(&_log_omp_lock);
            _log_omp_lock_initialized = 1;
        }
    }
}

static void _omplock()
{
    _ensure_log_omp_lock_initialized();
    omp_set_lock(&_log_omp_lock);
}

static void _ompunlock()
{
    omp_unset_lock(&_log_omp_lock);
}

static int _log(const char *format, ...)
{
        int err;
        va_list ap;

        va_start (ap, format);

        _ensure_log_omp_lock_initialized();
        _omplock();

        err = vfprintf (stderr, format, ap);

        _ompunlock();

        va_end(ap);

        return err;
}

int main (void)
{
        int pid, status;

        _log ("test\n");

        pid = fork();
        if (!pid)
        {
                _log ("test child\n");
                exit (0);
        }

        waitpid (pid, &status, 0);
        if (status != 0)
                _log ("child returned err=%d\n", status);
        exit (0);
}

 

It works on 11.1.056:

$ icc -V

Intel(R) C Intel(R) 64 Compiler Professional for applications running on Intel(R) 64, Version 11.1    Build 20090827 Package ID: l_cproc_p_11.1.056

Copyright (C) 1985-2009 Intel Corporation.  All rights reserved.

$ icc -Wall -openmp -g a.c -o a

tgcn5x64:/tmp$ ./a

test

test child

 

But don't work on 14.0.3

$ icc -V

Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 14.0.3.174 Build 20140422

Copyright (C) 1985-2014 Intel Corporation.  All rights reserved.

$ icc -Wall -openmp -g a.c -o a

$ ./a

teste

child returned err=139

Using GDB I get

Program received signal SIGSEGV, Segmentation fault.

[Switching to Thread 0x2aaaaade4800 (LWP 5984)]

0x00002aaaaab26bc9 in __kmp_lookup_user_lock (user_lock=0x601408, func=0x0) at ../../src/kmp_lock.cpp:3470

3470    ../../src/kmp_lock.cpp: No such file or directory.

        in ../../src/kmp_lock.cpp

(gdb) bt

#0  0x00002aaaaab26bc9 in __kmp_lookup_user_lock (user_lock=0x601408, func=0x0) at ../../src/kmp_lock.cpp:3470

#1  0x00002aaaaab0f352 in __kmpc_set_lock (loc=0x601408, gtid=0, user_lock=0x601408) at ../../src/kmp_csupport.c:1486

#2  0x0000000000400995 in _omplock () at a.c:26

#3  0x0000000000400a59 in _log (format=0x400c60 "test child\n") at a.c:42

#4  0x0000000000400b00 in main () at a.c:62

What am I doing wrong?

AdjuntoTamaño
Descargara.c1.09 KB

Viewing all articles
Browse latest Browse all 1616

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>