Search code examples
fortrangfortranexecutionexecution-timeconvergence

Is there a way to display the last part of my code ? The output of the last code lines doesn't appear


I am trying to execute a code using the gfortran compiler. In order to compile, I use :

gfortran -O3 hecese_seq.f90

In order to execute, I use :

./a.out

The code is below:

  compteur_tempo=0

  do while (.not.fin)
     
     compteur_tempo=compteur_tempo+1

     duree = duree+dt


     do pas=1,2

        tab0(:,:) =tab(:,:)

        !----------- CE/SE

        if(pas.eq.1)then

           do i=1,cpt,2
              flux(i)= tab0(i,3)*grad_x_u(i)
              sm(i)= dt/(dx)*flux(i) + dt**2/(4.0d0*dx)*grad_t_f(i) + dx/4.0*grad_x_u(i)
           enddo

           do i=2,cpt-1,2
              tab(i,2)= 0.5d0*( tab0(i+1,2)+tab0(i-1,2)+sm(i-1)-sm(i+1))    !-------Coord paires
           enddo

        else

           do i=2,cpt,2
              flux(i)= tab0(i,3)*grad_x_u(i)
              sm(i)= dt/(dx)*flux(i) + dt**2/(4.0d0*dx)*grad_t_f(i) + dx/4.0*grad_x_u(i)
           enddo

           do i=3,cpt-1,2
              tab(i,2)= 0.5d0*( tab0(i+1,2)+tab0(i-1,2)+sm(i-1)-sm(i+1))    !-------Coord impaires
           enddo

        endif
        
        !-------------- Traitement des interfaces - continuité du flux par la conductivité thermique

        do j=2,nb_element
           i = p_element(j)
           tab(i,2)=(tab(i-1,7)*tab(i-1,2)+tab(i+1,7)*tab(i+1,2))/(tab(i-1,7)+tab(i+1,7))
        enddo

        !-------------- Conditions cyclique sur la température

        tab(1,2)= 0.5d0*( tab0(2,2)+tab0(cpt-1,2)+sm(cpt-1)-sm(2))!2*dt/dx*(flux(1))-sm(2)-sm(1)+tab(2,2)!tab(2,2)!2000/T_ref!

        tab(cpt,2)=tab(1,2)!(-2*dt/dx)*flux(cpt)+sm(cpt-1)+sm(cpt)+tabi(cpt-1,2)!2000/T_ref!




        goto 113

        !---------------Resolution par Newton raphson - Actuellement inutilisé, je le laisse au cas où

        error=0.0d0
        test1=.true.
        itermax =10
        rhs(:)=tab(:,2)
        iter =0
        eps=1.0d-10
        DeltaT=1.0d-10
        sh(:)=0
        f1(:)=0
        f2(:)=0
        delt(:)=0

        do while((test1).and.(iter.le.itermax))
           iter = iter+1

           Call GRAD
           do j=pas+1,cpt-1,2
              sh(j)=tab(j,7)*tab(j,8)*grad_x_u(j)

              fluxnr(j) = -(tab(j,2)+(dt/2)*sh(j)-rhs(j))

              Delt(j)=fluxnr(j)

              tab(j,2) =tab(j,2)+delt(j)
           enddo
           error=0.0d0
           
           do j=2,cpt-1!,2!1,nb_element!
              error = max(error, abs(delt(j)))
           enddo

           if(iter.eq.itermax)then
              write(6,*)'itermax'
           endif

           test1=abs(error).ge.eps!.or.dabs(error).eq.0.0d0

        enddo


        !---------------Resolution des gradients

113     continue

        CALL GRAD

        do i=pas+1,cpt-1,2

           grad_x_f(i)= tab(i,3)*(tab(i+1,2)-2.0*tab(i,2)+tab(i-1,2))/(dx**2)!(Différence centrée deuxième ordre (dérivée seconde de la Temp)

           grad_t_u(i) = -grad_x_f(i)+tab(i,7)*grad_x_u(i)*tab(i,8)/2!(Terme source ajouté ici seulement - Légère influence sur les interfaces)

           grad_t_f(i) = grad_x_f(i)*tab(i,3)/(cfl*dx)!(Terme en dx/dt remplacé par tab(i,3)/(cfl*dx))

        enddo
        
        !------ Conditions cyclique - Gradients
        
        grad_x_f(cpt)=grad_x_f(cpt-1)
        grad_x_f(1)=grad_x_f(cpt)
        grad_t_u(cpt)=grad_t_u(cpt-1)
        grad_t_u(1)=grad_t_u(cpt)
        grad_t_f(cpt)=grad_t_f(cpt-1)
        grad_t_f(1)=grad_t_f(cpt)
        
        !------ Gradients moyennés sur l'interface (histoire de limiter les discontinuités)
        do j=2,nb_element
           i = p_element(j)
           grad_x_f(i)=(grad_x_f(i+1)+grad_x_f(i-1))/2
           grad_t_u(i)=(grad_t_u(i+1)+grad_t_u(i-1))/2
           grad_t_f(i)=(grad_t_f(i+1)+grad_t_f(i-1))/2
        enddo

     enddo


     !-------------- Test de la fonte de l'electrolite

     test = .false.
     i_ca_el = p_element(num)
     i_el_an = p_element(num+1)
     i=i_ca_el
     do while(((i.lt.i_el_an-1).and.(.not.test)))

        test=tab(i,2).le.(T_fonte)!20000)! Choix entre température d'équilibre ou température de fonte

        i = i+1

     enddo

     if(i.ge.i_el_an-1)convergence =.true.
     if(convergence) then
        write(6,*)'Convergence',i, i_ca_el,i_el_an-1, duree*time_ref
     else
        write(6,'(''Non Convergence'', 3i5,3f18.12)'),i, i_ca_el,i_el_an-1,tab(i,2)*t_ref,duree*time_ref
     endif

     if(.not.stock)then
        if( convergence.and.(duree.lt.duree_totale))then

           open(10,file='test'//char(ww+48)//'.dat', status='unknown')

           do i=1,cpt
              write(10,*)tab(i,1)*l_ref,tab(i,2)*t_ref
           enddo

           close(10)

           stock=.true.
           stop
        endif
     endif

     fin=duree.ge.duree_totale
     pas_stockage = pas_stockage+dt

     if(pas_stockage.ge.intervalle_stockage)then

        do i=1,nb_probe
           write(w_output(i),*)duree*time_ref, tab(probe_indice(i),2)*t_ref
        enddo

        pas_stockage =0.0d0
     endif

  enddo

!execution time 
      CALL CPU_TIME(TIME_END)
      call  system_clock(count=t2, count_rate=ir)
      write(*,*)" duree =  ",duree,duree*time_ref
      write(*,*)"compteur temporel ",compteur_tempo
      write(*,*)"cpt ",cpt
      write(*,*)" temps d’excecution  du  programme",TIME_END-TIME_START
      temps=real(t2 - t1 ,kind =8)/real(ir,kind =8)
      write  (*,*) "temps d’exe  du  programme:",temps
      do i=1,nb_probe
         close(w_output(i))
      enddo

For the part testing the convergence, it's okay but I don't get the execution time as I wanted to display it. I feel that the last part doesn't get executed. (maybe due to the "Stop" used for testing the convergence).

For the execution, I get:

Non Convergence  222  184  303  699.993372185986    0.340103428568
Non Convergence  222  184  303  699.993948217854    0.340103999997
Non Convergence  222  184  303  699.994524248306    0.340104571426
Non Convergence  222  184  303  699.995100277341    0.340105142854
Non Convergence  222  184  303  699.995676304960    0.340105714283
Non Convergence  222  184  303  699.996252331162    0.340106285711
Non Convergence  222  184  303  699.996828355948    0.340106857140
Non Convergence  222  184  303  699.997404379318    0.340107428568
Non Convergence  222  184  303  699.997980401271    0.340107999997
Non Convergence  222  184  303  699.998556421807    0.340108571426
Non Convergence  222  184  303  699.999132440928    0.340109142854
Non Convergence  222  184  303  699.999708458632    0.340109714283
Non Convergence  222  184  303  700.000284474919    0.340110285711
Non Convergence  222  184  303  700.000860489791    0.340110857140
Non Convergence  222  184  303  700.001436503245    0.340111428568
Non Convergence  222  184  303  700.002012515283    0.340111999997
Non Convergence  222  184  303  700.002588525905    0.340112571426
Non Convergence  222  184  303  700.003164535111    0.340113142854
Non Convergence  222  184  303  700.003740542900    0.340113714283
Non Convergence  222  184  303  700.004316549273    0.340114285711
Non Convergence  222  184  303  700.004892554230    0.340114857140
Non Convergence  222  184  303  700.005468557770    0.340115428568
Non Convergence  222  184  303  700.006044559894    0.340115999997
Non Convergence  222  184  303  700.006620560601    0.340116571426
Non Convergence  222  184  303  700.007196559892    0.340117142854
 Convergence         303         184         303  0.34011771428275706     
Note: The following floating-point exceptions are signalling: IEEE_UNDERFLOW_FLAG IEEE_DENORMAL

I showed you a small part of the execution (there are a lot of values so no need to show them all).

My problem is that I can't display the execution time while it has been already implemented. I'm new on this website so I hope you can help me.


Solution

  • Your structure basically is

    do
    
      !do something
    
      if (convergence) STOP
    
    end do
    
    

    That means that at convergence the program stops completely and you never get past the loop.

    To be able to continue execution after the loop you want to just exit the loop.

    do
    
      !do something
    
      if (convergence) EXIT
    
    end do
    
    !further statements