Specify OpenMP to GCC

前端 未结 1 1611
别那么骄傲
别那么骄傲 2021-02-01 17:29

For OpenMP, when my code is using the functions in its API (for example, omp_get_thread_num()) without using its directives (such as those #pragma omp ...),

  1. wh

1条回答
  •  清歌不尽
    2021-02-01 17:57

    In general, keep in mind that the directives and the functions are different things; the former are controlled by -fopenmp and the latter are controlled by linking to the OpenMP library.

    1. (Updated to incorporate comments) Try using the -fopenmp and -static options to statically link OpenMP. Because this implies -lgomp -lrt, the following command won't compile correctly unless you also specify the location of librt.a.

      gcc hello.c /usr/lib/gcc/i686-linux-gnu/4.4/libgomp.a  -o hello
      
    2. (Updated to incorporate comments) I imagine that the following command is compiling correctly because the OpenMP library is already in your library path and your system's dynamic linker is automatically linking with libgomp.so.

      gcc hello.c -fopenmp -o hello
      
    3. The following command is probably compiling properly because it is linking to the shared object for OpenMP (libgomp.so). Note that the -static option is not used.

      gcc hello.c -L/usr/lib/gcc/i686-linux-gnu/4.4/ -lgomp -o hello
      

      If you don't specify the -fopenmp option, OpenMP directives should be ignored.

    0 讨论(0)
提交回复
热议问题