Hello!
I'm looking to use Julia for an upcoming project and right now I'm trying 
to do a simple example which includes everything I need.I managed to 
port/code the application and the results are correct. Now I'm stuck trying 
to parallelize it.

My experience is with MPI on C. I use broadcast + allgather to have 
separate nodes compute and fill parts of a multi-dimensional array and 
otherwise all nodes doing the same thing. I'm not sure how to translate 
that into Julia's way of doing things. I'm trying distribute arrays.

Another complication is that I need to use SLURM to schedule jobs. So, my 
questions are:

1) was anyone successful running DArray code with SLURM?

2) any idea why I get this output:

Iteration 1
(11,100), DArray{Float64,2,Array{Float64,2}}
(1:0,1:0)
elapsed time: 2.388602661 seconds
Err = 0.0


when I run this code

using MAT;
using Grid;
using NLopt;

const alpha = 0.25;
const uBeta = 0.90;
const delta = 1.00;

const kGridMin = 0.01;
const kGridMax = 0.50;
const kGridSize = 100;

const vErrTol = 1e-8;
const maxIter = 200;

file = matopen("shock.mat")
yData = read(file, "y");
yGridSize = size(yData, 1);
y = linrange(yData[1], yData[end], yGridSize);
yPi = read(file, "yPi")
close(file)

function sgmVfi()
addprocs(24);
kGrid = linrange(kGridMin, kGridMax, kGridSize);
 V0 = zeros(yGridSize, kGridSize);
V1 = zeros(size(V0));
kPr = zeros(size(V0));

gdp(yIx, kIx) = exp(y[yIx]) * kGrid[kIx].^alpha;

iter = 0;
err = 1.0;
while iter < maxIter && err > vErrTol
tic();
iter += 1;
println("Iteration ", iter);
V0 = copy(V1);
V0f = CoordInterpGrid( (y, kGrid), V0, BCnearest, InterpQuadratic);

DV1 = distribute(V1);
DkPr = distribute(kPr);

println(size(DV1), ", ", typeof(DV1));

myIx = localindexes(DV1);
println(myIx);
for yIx = myIx[1]
for kIx = myIx[2]
println(yIx, " ", kIx, " ", myid());
opt = Opt(:LN_BOBYQA, 1)
lower_bounds!(opt, kGridMin)
upper_bounds!(opt, min(kGridMax, gdp(yIx, kIx)  + (1-delta) * kGrid[kIx] - 
1e-5))

myObj(kk) = log(gdp(yIx, kIx) - kk + (1-delta) * kGrid[kIx]) + uBeta * sum( 
[ yPi[yIx,yPrIx] * V0f[y[yPrIx], kk] for yPrIx = 1:yGridSize ]);

max_objective!(opt, (x::Vector, grad::Vector) -> myObj(x[1]) );
(maxVal, maxK, ret) = optimize!(opt, [kGridMin] );
localpart(DkPr)[yIx, kIx] = maxK[1];
localpart(DV1)[yIx, kIx] = maxVal;
end
end

V1 = convert(typeof(V1), DV1);
kPr = convert(typeof(kPr), DkPr);

err = maximum(abs(V1[:] - V0[:]));
toc()
println("Err = ", err)
end

return kGrid, V1, kPr;
end

kGrid, V, kPr = sgmVfi()



using this submission script:

#!/bin/bash
#SBATCH -J sgmVfi

#SBATCH -e elog_sgm
#SBATCH -o olog_sgm

#SBATCH -t 1:00:00

#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --cpus-per-task=24

#SBATCH -p standard
#SBATCH --mail-type=fail

module load julia
srun julia -q sgm.j


but the code runs fine (iterates 157 times and converges)when I just call 
the function from Julia and don't ask for procs (without paralleling but 
with DArray)?

3) Finally, if I call DV1 = distribute(V1) and DkPr = distribute(kPr) is 
there a way for me to make sure that localindexes(DV1) and 
localindexes(DkPr) return the same indices?

Any hint/lead is very much appreciated!

Thank you for your time!
Gabriel

Reply via email to