Segmentation fault - invalid memory reference in TFM simualtion

That output is a little confusing since the different processes are all writing to the same output and it’s getting mixed together. Here’s an improved version, where we only write data on processing element (PE) number 1:

        if((ep_s(IJK,1) .GT. ZERO) .AND. (Mug .GT. ZERO) &
            .AND. (ep_g(IJK) .GT. ZERO)) then
              !if (DEAD_CELL_AT(I,J,K)) cycle
              N_Power = -VOLPARTICLE * P_Grad_diff * VPARTICLE + &
              DgA * VRELA * VPARTICLE
              NUM =  (-VOLPARTICLE * P_Grad_diff + DgA * VRELA)
              DENOM = (3.0d0 * pi * Mug * DPM * ep_g(IJK) * VRELA)
              if (PE .eq. 1) then
                  write(*,*) "Mug=", Mug
                  write(*,*) "DPM=", DPM
                  write(*,*) "ep_g(", IJK, ")=", ep_g(IJK)
                  write(*,*) "VRELA=", VRELA
                  write(*,*) "NUM=", NUM
                  write(*,*) "DENOM=", DENOM
                  if (DENOM .EQ. 0) then
                      if (PE .eq. 1)  write(*,*) "WE HAVE A PROBLEM HERE!"
                   else
                       if (PE .eq. 1) write(*,*) "FRACTION=", NUM/DENOM
                       N_Fd = NUM/DENOM
                  end if

Output:

DEM NITs: 2   Total PIP: 9240
 Mug=   1.8499999999999999E-005
 DPM=   0.0000000000000000     
 ep_g(           0 )=   1.1931191281420263E-319
 VRELA=   0.0000000000000000     
 NUM=   0.0000000000000000     
 DENOM=   0.0000000000000000     
 WE HAVE A PROBLEM HERE!

 Mug=   1.8499999999999999E-005
 DPM=   0.0000000000000000     
 ep_g(           0 )=   1.1931191281420263E-319
 VRELA=   0.0000000000000000     
 NUM=   0.0000000000000000     
 DENOM=   0.0000000000000000     
 WE HAVE A PROBLEM HERE!

 Mug=   1.8499999999999999E-005
 DPM=   1.1999999999999999E-003
 ep_g(         815 )=  0.55539130995879105     
 VRELA=   1.2602140033530917     
 NUM=   1.8624048638473306E-004
 DENOM=   1.4644261762803337E-007
 FRACTION=   1271.7642541584919