Hello, I’m (still) beginning with Julia. I wrote a simple (and probably quite naive) function which calculate the annual numbers of frostdays (sum of days with temperature lower than 0 Celsius).
Since this calculation is “grid-point independent”, I’d like to use parallel calculation (single machine, with lots of core (96), as shown by the Sys.CPU_CORES
command). What would be the best way to do it?
Right now, the input array can be either a time x 1
, time x n
or time x m x n
Array.
Typical size of a matrix is like 40 000 x 5000 for 2D Array and 40 000 x 500 x 500 for a 3D Array.
Here’s the 2 methods for frostdays. Any suggestion is welcome, thanks!
function frostdays(data::Array{Float64, 2}, timeV::StepRange{Date, Base.Dates.Day})
numYears = unique(Dates.year(timeV))
FD = Array{Int64}(size(numYears, 1), size(data, 2))
z = 1
for iyear = numYears[1]:numYears[end]
fgYear = findin(Dates.year(timeV), iyear)
FD[z, :] = sum([isless(istep, 0) for istep in data[fgYear,:]], 1)
z = z + 1
end
return FD
end
function frostdays(data::Array{Float64, 3}, timeV::StepRange{Date, Base.Dates.Day})
numYears = unique(Dates.year(timeV))
FD = Array{Int64}(size(numYears, 1), size(data, 2), size(data, 3))
z = 1
for iyear = numYears[1]:numYears[end]
fgYear = findin(Dates.year(timeV), iyear)
FD[z, :, :] = sum([isless(istep, 0) for istep in data[fgYear,:]], 1)
z = z + 1
end
return FD
end