Fortran Coder

查看: 683|回复: 0
打印 上一主题 下一主题

[求助] help!!!

[复制链接]

1

帖子

1

主题

0

精华

新人

F 币
15 元
贡献
3 点
跳转到指定楼层
楼主
发表于 2024-5-12 19:13:25 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
大大们,我想请教一个问题。最近在写一个代码时,遇到了疑似内存泄漏/数组越界/并行不当...导致的程序bug,主要问题出现在gkk_vec这个数组上。代码主要是做了nstep次循环,里面还有nkpt的循环。在前4次kpt循环中,gkk_vec是正常被传递到fft里进行计算的,但是当kpt=5时,由文件读取进来(做了简单的数据处理)的gkk_vec(:,:,5)是正确的,但是我将gkk_vec用于fft时,gkk(:,393:ng(kpt),5))出现了错误。我尝试了很久还是没发现问题出在哪里,还请帮助我55555.主要的代码段如下:
[Fortran] 纯文本查看 复制代码
...
if (mod(istep,ngio)==0) then
    do ikpt=1,nkpt_per_proc
        kpt=proc_kpt_list(ikpt)
        filename = TRIM(dir) //'.save/'// label //TRIM(int_to_char(ikpt))//'_'//TRIM(int_to_char(starting_skip_step+istep))//'.dat'
        if (proc_id==0) write(6,*) 'extracted istep of MD from wfc file is ', istep_t, 'read filename is ', filename

        call MPI_BARRIER(MPI_COMM_WORLD,ierr)
        call read_wfcn(filename,wf)
        call MPI_BARRIER(MPI_COMM_WORLD,ierr)

        npol=wf%npol_
        nbnd=wf%nbnd_
        ng(kpt)=wf%igwx_
        if (proc_id==0) write(600+kpt+color,*) 'kpt is', kpt
        do ig=1,ng(kpt)
                gkk_vec(:,ig,kpt)=matmul(transpose(RL),wf%g(:,ig)) !unit: 1/Bohr
                if (proc_id==0) write(600+kpt+color,'(I,3F12.8)') ig, gkk_vec(:,ig,kpt)
        end do
        ug_tot=zero_cmp

        call MPI_BARRIER(MPI_COMM_WORLD,ierr)

        do istate=1,nstate_tot
                iistate=st1+istate-1
                do ig=1,ng(kpt)
                        ug_tot(ig,1,istate)=wf%bands(ig,1,iistate) !ug_tot(1:ngrid/2,:): up, ug_tot(ngrid/2+1:,:): dw
                end do  
                if (npol==2) then
                       do ig=1,ng(kpt)
                               ug_tot(ig,2,istate)=wf%bands(ig,2,iistate) !ug_tot(1:ngrid/2,:): up, ug_tot(ngrid/2+1:,:): dw
                       end do  
                end if
        end do
        if (proc_id==0) write(6,*) 'start to do FFT'

        call MPI_BARRIER(MPI_COMM_WORLD,ierr)

        if (color==0) then
            ug_r=zero_cmp
                write(900+kpt+color,*) 'kpt is', kpt
                do ig=1,ng(kpt)
                        write(900+kpt+color,'(I,3F12.8)') ig, gkk_vec(:,ig,kpt)
                end do

            call fft_states(n1, n2, n3, nstate, ng(kpt), ngrid, AL, gkk_vec(:,:,kpt), ug_tot(:,:,:nstate_h), ug_r,color,vol, kpt, npol) !up
            ug_r_up(:,:,:,:,kpt)=ug_r!(:,:,:,:)
            !call fft_states(n1, n2, n3, nstate, ng(kpt), ngrid, AL, gkk_vec(:,:,kpt), ug_tot(:,2,:nstate_h), ug_r_dw(:,:,:,:,kpt),color) !dw
        else if (color==1) then
            ug_r=zero_cmp
                write(1000+kpt+color,*) 'kpt is', kpt
                do ig=1,ng(kpt)
                        write(1000+kpt+color,'(I,3F12.8)')ig, gkk_vec(:,ig,kpt)
                end do
            call fft_states(n1, n2, n3, nstate, ng(kpt), ngrid, AL, gkk_vec(:,:,kpt), ug_tot(:,:,nstate_h+1:), ug_r,color,vol,kpt, npol) !up
            ug_r_up(:,:,:,:,kpt)=ug_r!(:,:,:,:)
            !call fft_states(n1, n2, n3, nstate, ng(kpt), ngrid, AL, gkk_vec(:,:,kpt), ug_tot(:,2,nstate_h+1:), ug_r_dw(:,:,:,:,kpt),color) !dw
        end if
...


分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-12-23 18:02

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表