MPI Fortran 编译错误 #6404: 'omp_get_thread_num()' 函数类型错误
在使用 MPI Fortran 编译器编译代码时,可能会遇到如下错误:
mpiifort -traceback -debug -O2 -static_intel -c -o processes.o processes.f90
processes.f90(147): error #6404: This name does not have a type, and must have an explicit type. [OMP_GET_THREAD_NUM]
if(myid==0 .and. omp_get_thread_num()==0) then
--------------------------^
compilation aborted for processes.f90 (code 1)
make: *** [Makefile:24: processes.o] Error 1
这个错误是因为编译器无法识别 'omp_get_thread_num()' 函数的类型,需要在代码中添加 USE OMP_LIB 来指定 OpenMP 库。修改后的代码应该类似于:
program main
use omp_lib
implicit none
integer :: myid, numprocs, thread_num, nthreads
!$omp parallel private(thread_num, nthreads)
thread_num = omp_get_thread_num()
nthreads = omp_get_num_threads()
!$omp end parallel
print *, 'Hello world from thread ', thread_num, ' of ', nthreads
end program main
请注意,这里的 USE OMP_LIB 语句应该在程序的开头,而不是在 if 语句中。
原文地址: https://www.cveoy.top/t/topic/nxpc 著作权归作者所有。请勿转载和采集!