Not really sure if I need mutable global actually.
I am a Fortran guy and I am new to Julia.
I am just translating my Fortran code to Julia.
In my Fortran code, I have modules, in the modules I have some variables and arrays defined at the top, which looks like the global stuff in Julia. Like below,
module step
use constants
use mixture
use formats
implicit none
real(kind=r8), private, allocatable, save :: Yji(:,:),t(:)
integer(kind=i8), private, save :: imode,iter,itermax &
,msample,mgauss,mgauss_tot,mgauss_max,mgauss_min,nsub,mi,mitot,dim_p,kmix
real(kind=r8), private, save :: tsum,mu1,sig1,mu2,sig2,muV,SigV,w1,w2,sig,sig_inv,sigsq2_inv,D &
,normpdf_factor_pYq_i,log_normpdf_factor_pYq_i,sigma_factor
real(kind=r8), private, allocatable, save :: LL_iter(:),muk_iter(:,:),sigk_iter(:,:) &
,muV_iter(:,:),sigV_iter(:,:),wk_iter(:,:),sigma_iter(:) &
,mukerror_iter(:,:),sigkerror_iter(:,:) &
,muVerror_iter(:,:),sigVerror_iter(:,:),sigmaerror_iter(:) &
,ar_gik(:),ar_gik_k(:,:) &
,thetas(:,:,:),thetaspr(:,:,:) &
,norm(:),norm_sig(:),normerr(:),log_norm(:) &
,pYq_ikm(:,:,:),hi_diag(:,:,:,:),yimhi(:,:,:,:) &
,pYq_km(:,:),log_pYq_km(:,:),h_diag(:,:,:),ymh(:,:,:) &
,pYq_ikm_o(:,:,:)
real(kind=r8), private, allocatable, save ::wnow(:),log_wnow(:),nik(:,:),nik_sig(:,:),wknik(:,:),wknik_sig(:,:),tauik(:,:)
integer(kind=i8), private, allocatable, save :: isub_Metroplis_gik_all(:,:),mgauss_ik(:,:)
...
contains
subroutine initialization(...)
blablabla
end
subroutine A(...)
...
end
subroutine B(...)
...
end
subroutine C(...)
...
end
...
...
end module step
All those r8 and i8 variables and allocable arrays are stored in the module, and their values can change. So that in my Fortran code, I do not need to put every of them in the arguments of any function.
But it seems in Julia, as many guys pointed out, people don’t do such things.
My Fortran code cannot be translated into Julia in a ‘raw’ way. So I need to think about it. It seems the translation will need to make some change. Otherwise my Julia version code will be way much slower than the Fortran code, and that lost the meaning of my translation.
It is a Monte Carlo Expectation Maximization code with various Metropolis samplings and iterations. Just wanted to see how fast is Julia compared with Fortran.