Вопрос

In my c++ project, there are several #pragma omp parallel for private(i) statements. When I try to track down bugs in my code using valgrind, the OpenMP adornments result in "possibly lost" memory leak messages. I would like to totally disable all of the aforementioned #pragma statements so that I can isolate the problem.

However, I use omp_get_wtime() in my code, and I do not wish to disable these function calls. So I don't want to totally disable all OpenMP functionality in my project.

How can I simply turn off all the #pragma omp parallel for private(i) statements?

I use Eclipse CDT to automatically manage makefiles, and so I normally compile in release mode by: make all -C release. Ideally, I would like a solution to my problem that permits me to compile using a statement such as make all -C release -TURN_OFF_PARALLEL which would result in all the aforementioned #pragma statements being turned off.

Это было полезно?

Решение

The simplest solution is to:

  1. disable OpenMP
  2. link the OpenMP stub library functions

In case your OpenMP implementation doesn't provide stub functions, you can create your own copying from Appendix B of the standard.

Другие советы

Following some dwelling around an interesting question about a non-working OpenMP code, it turns out that it is perfectly possible to get the equivalent of a stub OpenMP lib with GCC by only replacing the -fopenmp with -lgomp. I doubt it was a intended feature, but it works out of the box nonetheless.

For GCC I don't see an option to use only the stubs. Appendix B of the OpenMP standard says

    double omp_get_wtime(void)
    {
    /* This function does not provide a working
    * wallclock timer. Replace it with a version
    * customized for the target machine.
    */
    return 0.0;
    }

That's useless if you actually want the time. With GCC, either you have to write your own time function or you search for "#pragma omp" and replace it with "//#pragma omp"

Rather than changing the whole code base you could implement your own time function for GCC only. Computing time in linux :granularity and precision

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top