10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-11-07 06:33:39 +01:00

Fixed MPI Broadcast in FCI-f12

This commit is contained in:
Anthony Scemama 2020-01-21 22:31:30 +01:00
parent b8b1d3e1e0
commit 3dcaa33db6

View File

@ -47,31 +47,31 @@ let array_3_init d1 d2 d3 fx =
Parallel.Node.broadcast (lazy result) Parallel.Node.broadcast (lazy result)
let array_4_init d1 d2 d3 d4 fx = let array_4_init d1 d2 d3 d4 fx =
let f l = let f (k,l) =
let x = let x =
Bigarray.(Array3.create Float64 fortran_layout d1 d2 d3) Bigarray.(Array2.create Float64 fortran_layout d1 d2)
in in
for k=1 to d3 do
for j=1 to d2 do for j=1 to d2 do
for i=1 to d1 do for i=1 to d1 do
x.{i,j,k} <- fx i j k l x.{i,j} <- fx i j k l
done
done done
done; done;
(l,x) (k,l,x)
in in
let result = let result =
SharedMemory.create Bigarray.Float64 [| d1;d2;d3;d4 |] SharedMemory.create Bigarray.Float64 [| d1;d2;d3;d4 |]
in in
Util.list_range 1 d4 Util.list_range 1 d4
|> List.map (fun l ->
Util.list_range 1 d3
|> List.map (fun k -> (k,l)) )
|> List.concat
|> Stream.of_list |> Stream.of_list
|> Farm.run ~f |> Farm.run ~f
|> Stream.iter (fun (l,x) -> |> Stream.iter (fun (k,l,x) ->
for k=1 to d3 do
for j=1 to d2 do for j=1 to d2 do
for i=1 to d1 do for i=1 to d1 do
result.{i,j,k,l} <- x.{i,j,k} result.{i,j,k,l} <- x.{i,j}
done
done done
done) done)
; ;
@ -79,28 +79,64 @@ let array_4_init d1 d2 d3 d4 fx =
Parallel.Node.broadcast (lazy result) Parallel.Node.broadcast (lazy result)
let array_5_init d1 d2 d3 d4 d5 fx = let array_5_init d1 d2 d3 d4 d5 fx =
let f m = let f (l,m) =
let x = let x =
Bigarray.(Genarray.create Float64 fortran_layout [| d1; d2; d3; d4 |]) Bigarray.(Array3.create Float64 fortran_layout d1 d2 d3)
in in
for l=1 to d4 do
for k=1 to d3 do for k=1 to d3 do
for j=1 to d2 do for j=1 to d2 do
for i=1 to d1 do for i=1 to d1 do
x.{i,j,k,l} <- fx i j k l m x.{i,j,k} <- fx i j k l m
done
done done
done done
done; done;
(m,x) (l,m,x)
in in
let result = let result =
SharedMemory.create Bigarray.Float64 [| d1;d2;d3;d4;d5 |] SharedMemory.create Bigarray.Float64 [| d1;d2;d3;d4;d5 |]
in in
Util.list_range 1 d5 Util.list_range 1 d5
|> List.map (fun m ->
Util.list_range 1 d4
|> List.map (fun l -> (l,m)) )
|> List.concat
|> Stream.of_list |> Stream.of_list
|> Farm.run ~f |> Farm.run ~f
|> Stream.iter (fun (m,x) -> |> Stream.iter (fun (l,m,x) ->
for k=1 to d3 do
for j=1 to d2 do
for i=1 to d1 do
result.{i,j,k,l,m} <- x.{i,j,k}
done
done
done)
;
if Parallel.master then Printf.printf "Broadcast d5\n" ;
try
Parallel.Node.broadcast (lazy result)
with Invalid_argument _ ->
begin
Printf.eprintf "Array too large... splitting.\n%!";
let x =
Bigarray.(Genarray.create Float64 fortran_layout [| d1; d2; d3; d4 |])
in
for m=1 to d5 do
if Parallel.master then
begin
for l=1 to d4 do
for k=1 to d3 do
for j=1 to d2 do
for i=1 to d1 do
x.{i,j,k,l} <- result.{i,j,k,l,m}
done
done
done
done;
ignore @@ Parallel.Node.broadcast (lazy x)
end
else
begin
ignore @@ Parallel.Node.broadcast (lazy x);
for l=1 to d4 do for l=1 to d4 do
for k=1 to d3 do for k=1 to d3 do
for j=1 to d2 do for j=1 to d2 do
@ -109,10 +145,11 @@ let array_5_init d1 d2 d3 d4 d5 fx =
done done
done done
done done
done) done
; end
if Parallel.master then Printf.printf "Broadcast d5\n" ; done;
Parallel.Node.broadcast (lazy result) result
end
let make ~simulation ~mo_basis ~aux_basis_filename () = let make ~simulation ~mo_basis ~aux_basis_filename () =
@ -938,8 +975,7 @@ let make ~simulation ~mo_basis ~aux_basis_filename () =
f_0 ; f_1 ; f_2 ; f_3 f_0 ; f_1 ; f_2 ; f_3
} }
in in
if Parallel.master then Printf.printf "Broadcast f3\n" ; result
Parallel.broadcast (lazy result)