编译OpenMP程序的时候,需要在编译源文件和连接时都加入‘-fopenmp’编译选项。
以Code::Blocks13.11为例,需要在‘Project‘-‘Build Option‘-‘Compiler Flags‘中勾选‘Enable the OpenMP extensions [-fopenmp]‘;
在同一窗口的‘Linker Settings’-‘Other Linker Options’中加入“-fopenmp”
环境设置完毕,可以进行程序编辑了。
program main implicit none include ‘omp_lib.h‘ integer :: threadCount integer :: threadNum !$OMP PARALLEL PRIVATE(threadCount, threadNum) threadCount = OMP_GET_NUM_THREADS() threadNum = OMP_GET_THREAD_NUM() write(*, "(‘THREAD: ‘, I2, ‘/‘, I2)") threadNum, threadCount !$OMP END PARALLEL end program