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

Working on parallel

This commit is contained in:
Anthony Scemama 2018-10-16 19:09:00 +02:00
parent 408b7692a6
commit be47e1c9c3
7 changed files with 166 additions and 30 deletions

View File

@ -21,6 +21,15 @@ export LACAML_LIBS="-L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_rt -lpthr
opam install lacaml opam install lacaml
``` ```
To use Intel MPI
```bash
export MPI_INC_DIR=${I_MPI_ROOT}/include64/
export MPI_LIB_DIR=${I_MPI_ROOT}/lib64/
export MPI_BIN_PATH=${I_MPI_ROOT}/bin64/
opam install mpi
```
# odoc-ltxhtml # odoc-ltxhtml
This plugin allows to embed equations in the documentation generated by Ocamldoc. This plugin allows to embed equations in the documentation generated by Ocamldoc.

View File

@ -3,7 +3,7 @@
INCLUDE_DIRS=Parallel,Nuclei,Utils,Basis,SCF,MOBasis,CI INCLUDE_DIRS=Parallel,Nuclei,Utils,Basis,SCF,MOBasis,CI
LIBS= LIBS=
PKGS= PKGS=
OCAMLBUILD=ocamlbuild -j 0 -cflags $(ocamlcflags) -lflags $(ocamlcflags) $(ocamldocflags) -Is $(INCLUDE_DIRS) -ocamlopt $(ocamloptflags) OCAMLBUILD=ocamlbuild -j 0 -cflags $(ocamlcflags) -lflags $(ocamllflags) $(ocamldocflags) -Is $(INCLUDE_DIRS) -ocamlopt $(ocamloptflags)
MLLFILES=$(wildcard */*.mll) $(wildcard *.mll) Utils/math_functions.c MLLFILES=$(wildcard */*.mll) $(wildcard *.mll) Utils/math_functions.c
MLYFILES=$(wildcard */*.mly) $(wildcard *.mly) MLYFILES=$(wildcard */*.mly) $(wildcard *.mly)

View File

@ -1,6 +1,76 @@
(** Module for handling distributed parallelism *) (** Module for handling distributed parallelism *)
let size = Mpi.comm_size Mpi.comm_world let size =
let rank = Mpi.comm_rank Mpi.comm_world let result =
Mpi.comm_size Mpi.comm_world
in
assert (result > 0);
result
let rank =
let result =
Mpi.comm_rank Mpi.comm_world
in
assert (result >= 0);
result
let barrier () =
Mpi.barrier Mpi.comm_world
module Vec = struct
type t =
{
global_first : int ; (* Lower index in the global array *)
global_last : int ; (* Higher index in the global array *)
local_first : int ; (* Lower index in the local array *)
local_last : int ; (* Higher index in the local array *)
data : Lacaml.D.vec ; (* Lacaml vector containing the data *)
}
let pp ppf v =
Format.fprintf ppf "@[<2>";
Format.fprintf ppf "@[ gf : %d@]@;" v.global_first;
Format.fprintf ppf "@[ gl : %d@]@;" v.global_last;
Format.fprintf ppf "@[ lf : %d@]@;" v.local_first;
Format.fprintf ppf "@[ ll : %d@]@;" v.local_last;
Format.fprintf ppf "@[ data : %a@]@;" (Lacaml.Io.pp_lfvec ()) v.data;
Format.fprintf ppf "@]@.";
()
let create n =
let step = n / size + 1 in
let local_first = step * rank + 1 in
let local_last = min (local_first + step - 1) n in
{
global_first = 1 ;
global_last = n ;
local_first ;
local_last ;
data = Lacaml.D.Vec.create (local_last - local_first + 1)
}
let make n x =
let result = create n in
{ result with data =
Lacaml.D.Vec.make
(Lacaml.D.Vec.dim result.data)
x
}
let make0 n =
make n 0.
let init n f =
let result = create n in
{ result with data =
Lacaml.D.Vec.init
(Lacaml.D.Vec.dim result.data)
(fun i -> f (i+result.local_first-1))
}
end

View File

@ -4,7 +4,82 @@ val size : int
(** Number of distributed processes. *) (** Number of distributed processes. *)
val rank : Mpi.rank val rank : Mpi.rank
(** Rannk of the current distributed processe. *) (** Rank of the current distributed processe. *)
val barrier : unit -> unit
(** Wait for all processes to reach this point. *)
(** {5 Vector operations} *)
module Vec : sig
type t =
{
global_first : int ; (* Lower index in the global array *)
global_last : int ; (* Higher index in the global array *)
local_first : int ; (* Lower index in the local array *)
local_last : int ; (* Higher index in the local array *)
data : Lacaml.D.vec ; (* Lacaml vector containing the data *)
}
val pp : Format.formatter -> t -> unit
(** {6 Creation/conversion of vectors and dimension accessor} *)
val create : int -> t
(** [create n] @return a distributed vector with [n] rows (not initialized). *)
val make : int -> float -> t
(** [make n x] @return a distributed vector with [n] rows initialized with value [x]. *)
val make0 : int -> t
(** [make0 n x] @return a distributed vector with [n] rows initialized with the zero
element. *)
val init : int -> (int -> float) -> t
(** [init n f] @return a distributed vector containing [n] elements, where
each element at position [i] is initialized by the result of calling [f i]. *)
(*
val of_array : float array -> t
(** [of_array ar] @return a distributed vector initialized from array [ar]. *)
val to_array : t -> float array
(** [to_array v] @return an array initialized from vector [v]. *)
val of_vec : Lacaml.D.vec -> t
(** [of_vec vec] @return a distributed vector initialized from Lacaml vector [vec]. *)
val to_vec : t -> Lacaml.D.vec
(** [to_vec v] @return a Lacaml vector initialized from vector [v]. *)
*)
end
(*
module Mat : sig
type t =
{
global_first_row : int ; (* Lower row index in the global array *)
global_last_row : int ; (* Higher row index in the global array *)
global_first_col : int ; (* Lower column index in the global array *)
global_last_col : int ; (* Higher column index in the global array *)
local_first_row : int ; (* Lower row index in the local array *)
local_last_row : int ; (* Higher row index in the local array *)
local_first_col : int ; (* Lower column index in the local array *)
local_last_col : int ; (* Higher column index in the local array *)
data : Lacaml.D.mat ; (* Lacaml matrix containing the data *)
}
end
val gemm : Mat.t -> Mat.t -> Mat.t
(* Distributed matrix-matrix product. The result is a distributed matrix. *)
val dot : Vec.t -> Vec.t-> float
(* Dot product between distributed vectors. *)
*)

View File

@ -1,6 +1,7 @@
Requirements Requirements
------------ ------------
* MPI : Message Passing Interface
* BLAS/LAPACK : Linear algebra * BLAS/LAPACK : Linear algebra
* LaCaml : LAPACK OCaml interface * LaCaml : LAPACK OCaml interface
* Zarith : Arbitrary-precision integers * Zarith : Arbitrary-precision integers
@ -8,3 +9,6 @@ Requirements
* odoc-ltxhtml : https://github.com/akabe/odoc-ltxhtml * odoc-ltxhtml : https://github.com/akabe/odoc-ltxhtml
* Alcotest : Lightweight testing framework * Alcotest : Lightweight testing framework
Troubleshooting
---------------

24
opam
View File

@ -1,24 +0,0 @@
opam-version: "1.2"
name: "QCaml"
version: "0.1"
maintainer: "Anthony Scemama <scemama@irsamc.ups-tlse.fr>"
authors: "Anthony Scemama <scemama@irsamc.ups-tlse.fr>"
homepage: "http://github.com/scemama/QCaml"
#bug-reports: ""
#license: ""
dev-repo: "http://github.com/scemama/QCaml"
build: [
["./configure" "-prefix" "%{prefix}%"]
[make]
]
install: [make "install"]
remove: [
["./configure" "-prefix" "%{prefix}%"]
[make "uninstall"]
["ocamlfind" "remove" "QCaml"]
]
depends: [
"ocamlfind" "lacaml" "alcotest" {build}
]

View File

@ -1,5 +1,7 @@
let () = let () =
Printf.printf "Hello from rank %d of %d.\n" Printf.printf "Hello from rank %d of %d.\n" Parallel.rank Parallel.size;
Parallel.rank Parallel.size let () = Parallel.barrier () in
let v = Parallel.Vec.init 47 (fun i -> float_of_int i) in
Format.printf "%a" Parallel.Vec.pp v;