相关疑难解决方法(0)

为什么在这个openmp代码中发生了分段错误?

主程序:

program main                                                                                                                                                    
  use omp_lib                                                                                                                                                   
  use my_module                                                                                                                                                 
  implicit none                                                                                                                                                 

  integer, parameter :: nmax = 202000                                                                                                                           
  real(8) :: e_in(nmax) = 0.D0                                                                                                                                  
  integer i                                                                                                                                                     

call omp_set_num_threads(2)                                                                                                                                     
!$omp parallel default(firstprivate)                                                                                                                            
!$omp do                                                                                                                                                        
  do i=1,2                                                                                                                                                      
     print *, e_in(i)                                                                                                                                           
     print *, eTDSE(i)                                                                                                                                          
  end do                                                                                                                                                        
!$omp end do                                                                                                                                                    
!$omp end parallel                                                                                                                                              
end program main
Run Code Online (Sandbox Code Playgroud)

模块:

module my_module                                                                                                                                                
  implicit none                                                                                                                                                 

  integer, parameter, private :: ntmax = 202000                                                                                                  
  double complex :: eTDSE(ntmax) = (0.D0,0.D0)                                                                                                                  
!$omp threadprivate(eTDSE)                                                                                                                                      

end module my_module
Run Code Online (Sandbox Code Playgroud)

编译使用:

ifort -openmp main.f90 my_module.f90
Run Code Online (Sandbox Code Playgroud)

它在执行时给出Segmentation故障.如果删除主程序中的一个打印命令,它运行正常.另外如果删除omp函数并在没有-openmp选项的情况下编译,它也运行正常.

fortran openmp

17
推荐指数
2
解决办法
2万
查看次数

标签 统计

fortran ×1

openmp ×1