mirror of
https://gitlab.com/scemama/qmcchem.git
synced 2024-11-09 07:33:39 +01:00
Compare commits
16 Commits
5befb6dfe9
...
161900c87a
Author | SHA1 | Date | |
---|---|---|---|
161900c87a | |||
be84027a8c | |||
1e99c27416 | |||
e0e7c73adc | |||
f26b8fd9c5 | |||
cb7d8a1e4f | |||
35a083f6f3 | |||
b0fa735311 | |||
f7ffed3a5a | |||
380169d219 | |||
5e25738f53 | |||
b14fe1dc34 | |||
a13410d277 | |||
a719c694ce | |||
4c870cb62b | |||
16acf1fe89 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,3 @@
|
||||
.ninja_deps
|
||||
.ninja_log
|
||||
EZFIO
|
||||
install/Downloads
|
||||
install/_build
|
||||
|
66
Makefile
Normal file
66
Makefile
Normal file
@ -0,0 +1,66 @@
|
||||
include make.config
|
||||
|
||||
|
||||
default_target: all
|
||||
|
||||
.phony: clean always
|
||||
|
||||
clean:
|
||||
./scripts/clean.sh
|
||||
|
||||
# put all files of PROPERTIES here
|
||||
# --------------------------------
|
||||
|
||||
ezfio_config/properties.config ocaml/Property.ml: scripts/create_properties_python.py src/PROPERTIES/properties.irp.f src/PROPERTIES/properties_energy.irp.f src/PROPERTIES/properties_general.irp.f src/irpf90.make
|
||||
bash -c "source qmcchemrc ; exec python2 ./scripts/create_properties_ezfio.py"
|
||||
|
||||
# EZFIO
|
||||
# -----
|
||||
|
||||
build lib/libezfio.a lib/libezfio_irp.a EZFIO/lib/libezfio.a EZFIO/lib/libezfio_irp.a EZFIO/Ocaml/ezfio.ml EZFIO/Python/ezfio.py: ezfio_config/qmc.config ezfio_config/properties.config make.config scripts/create_properties_ezfio.py src/tags src/irpf90_entities src/irpf90.make src/irpf90.make
|
||||
./scripts/compile_ezfio.sh
|
||||
|
||||
|
||||
# Fortran executables
|
||||
# -------------------
|
||||
|
||||
|
||||
always: /dev/null
|
||||
|
||||
src/tags src/irpf90_entities src/irpf90.make: make.config always
|
||||
./scripts/compile_irpf90.sh
|
||||
|
||||
src/MAIN/qmc src/MAIN/qmc_create_walkers src/MAIN/qmcchem_info: lib/libezfio.a lib/libezfio_irp.a src/tags src/irpf90_entities src/irpf90.make src/irpf90.make
|
||||
./scripts/compile_src.sh
|
||||
|
||||
# OCaml
|
||||
# -----
|
||||
|
||||
ocaml/qmcchem: EZFIO/Ocaml/ezfio.ml $(wildcard ocaml/*.ml)
|
||||
./scripts/compile_ocaml.sh
|
||||
|
||||
# Archive
|
||||
# -------
|
||||
|
||||
qmcchem.tar.gz: all
|
||||
git archive --format tar.gz HEAD --prefix "QmcChem/" -7 -o qmcchem.tar.gz
|
||||
|
||||
|
||||
# Binaries
|
||||
# --------
|
||||
|
||||
bin/qmc: src/MAIN/qmc
|
||||
cp src/MAIN/qmc bin/
|
||||
|
||||
bin/qmcchem_info: src/MAIN/qmcchem_info
|
||||
cp src/MAIN/qmcchem_info bin/
|
||||
|
||||
bin/qmc_create_walkers: src/MAIN/qmc_create_walkers
|
||||
cp src/MAIN/qmc_create_walkers bin/
|
||||
|
||||
bin/qmcchem: ocaml/qmcchem
|
||||
cp ocaml/qmcchem bin/
|
||||
|
||||
all: bin/qmc bin/qmcchem_info bin/qmc_create_walkers bin/qmcchem
|
||||
|
||||
|
23
README.md
23
README.md
@ -35,13 +35,12 @@ Warnings:
|
||||
Requirements
|
||||
------------
|
||||
|
||||
* [Ninja build tool](http://github.com/martine/ninja)
|
||||
* [OCaml compiler with Opam and Core library](http://github.com/ocaml)
|
||||
* [ZeroMQ high performance communication library](http://www.zeromq.org)
|
||||
* [F77_ZMQ ZeroMQ Fortran interface](http://github.com/scemama/f77_zmq/)
|
||||
* [IRPF90 Fortran code generator](http://irpf90.ups-tlse.fr)
|
||||
* [EZFIO Easy Fortran I/O library generator](http://github.com/scemama/EZFIO)
|
||||
* GNU C++ Compiler (g++) for ZeroMQ and Ninja
|
||||
* GNU C++ Compiler (g++) for ZeroMQ
|
||||
* Python >= 2.6 for install scripts
|
||||
* Bash for install scripts
|
||||
* Fortran compiler, Intel Fortran recommended
|
||||
@ -58,9 +57,8 @@ Installation
|
||||
The ``make.config`` file contains compiler specific parameters. You should change
|
||||
them to match your hardware.
|
||||
|
||||
The ``configure.sh`` script will first download the
|
||||
[Ninja](http://github.com/martine/ninja) build tool, and will then run Ninja
|
||||
using the ``install/build.ninja`` file. The configuration script will work in
|
||||
The ``configure.sh`` script will first download the dependencies by running
|
||||
``make`` in the ``install/`` directory. The configuration script will work in
|
||||
the ``install`` directory. It will first download into the
|
||||
``install/Downloads`` directory everything that needs to be installed.
|
||||
The building of the dependencies takes place in the ``install/_build``
|
||||
@ -80,17 +78,20 @@ environment variables are located in the ``qmcchemrc`` file:
|
||||
$ source qmcchemrc
|
||||
```
|
||||
|
||||
The ``QMCCHEM_NIC`` environment variable should be set to the proper network interface,
|
||||
usually ``ib0`` on HPC machines.
|
||||
|
||||
To compile the program, run
|
||||
|
||||
```bash
|
||||
$ ninja
|
||||
$ make
|
||||
```
|
||||
|
||||
|
||||
Example of a QMC=Chem calculation
|
||||
---------------------------------
|
||||
|
||||
1.Calculation with the [quantum package](http://github.com/LCPQ/quantum_package)
|
||||
1.Calculation with the [quantum package](http://github.com/QuantumPackage/qp2)
|
||||
|
||||
|
||||
Create the `xyz` file containing the nuclear coordinates of the system
|
||||
@ -108,18 +109,18 @@ EOF
|
||||
Choose a suitable basis set and create the [EZFIO database](https://github.com/LCPQ/ezfio)
|
||||
|
||||
```bash
|
||||
$ qp_create_ezfio_from_xyz -b cc-pvdz h2o.xyz -o h2o
|
||||
$ qp_create_ezfio -b cc-pvdz h2o.xyz -o h2o
|
||||
```
|
||||
|
||||
Run the SCF calculation
|
||||
|
||||
```bash
|
||||
$ qp_run SCF h2o
|
||||
$ qp_run scf h2o
|
||||
```
|
||||
Run the CIPSI calculation
|
||||
|
||||
```bash
|
||||
$ qp_run full_ci h2o
|
||||
$ qp_run fci h2o
|
||||
```
|
||||
|
||||
Transform the input for use in QMC=Chem
|
||||
@ -135,7 +136,7 @@ $ qp_run save_for_qmcchem h2o
|
||||
Before using QMC=Chem, you need to load the environment variables:
|
||||
|
||||
```bash
|
||||
$ source qmcchem.rc
|
||||
$ source qmcchemrc
|
||||
```
|
||||
|
||||
In QMC=Chem, everything goes through the use of the ``qmcchem`` command.
|
||||
|
88
build.ninja
88
build.ninja
@ -1,88 +0,0 @@
|
||||
rule compile_ezfio
|
||||
command = ./scripts/compile_ezfio.sh
|
||||
description = Compiling the EZFIO library
|
||||
pool = console
|
||||
|
||||
rule build_properties_config
|
||||
command = bash -c "source qmcchemrc ; exec python2 ./scripts/create_properties_ezfio.py"
|
||||
pool = console
|
||||
|
||||
rule compile_irpf90
|
||||
command = ./scripts/compile_irpf90.sh
|
||||
description = Compiling IRPF90
|
||||
pool = console
|
||||
|
||||
rule compile_src
|
||||
command = ./scripts/compile_src.sh
|
||||
description = Compiling src
|
||||
pool = console
|
||||
|
||||
rule create_archive
|
||||
command = git archive --format tar.gz HEAD --prefix "QmcChem/" -7 -o qmcchem.tar.gz
|
||||
description = Creating archive
|
||||
pool = console
|
||||
|
||||
rule compile_ocaml_dep
|
||||
command = scripts/compile_ocaml_dep.sh
|
||||
description = Finding dependencies in OCaml files
|
||||
pool = console
|
||||
|
||||
rule compile_ocaml
|
||||
command = cd ocaml ; ninja $target
|
||||
description = Compiling OCaml tools
|
||||
pool = console
|
||||
|
||||
rule copy_to_bin
|
||||
command = bash -c "cp $in $out ; touch $out"
|
||||
description = Copying $in into bin/
|
||||
pool = console
|
||||
|
||||
rule clean
|
||||
command = ./scripts/clean.sh
|
||||
pool = console
|
||||
|
||||
# put all files of PROPERTIES here
|
||||
# --------------------------------
|
||||
|
||||
build ezfio_config/properties.config ocaml/Property.ml: build_properties_config | scripts/create_properties_python.py src/PROPERTIES/properties.irp.f src/PROPERTIES/properties_energy.irp.f src/PROPERTIES/properties_general.irp.f || src/IRPF90_temp/build.ninja
|
||||
|
||||
# EZFIO
|
||||
# -----
|
||||
|
||||
build lib/libezfio.a lib/libezfio_irp.a EZFIO/lib/libezfio.a EZFIO/lib/libezfio_irp.a EZFIO/Ocaml/ezfio.ml EZFIO/Python/ezfio.py: compile_ezfio | ezfio_config/qmc.config ezfio_config/properties.config make.config scripts/create_properties_ezfio.py || src/tags src/irpf90_entities src/irpf90.make src/IRPF90_temp/build.ninja
|
||||
|
||||
# Fortran executables
|
||||
# -------------------
|
||||
|
||||
build always: phony
|
||||
|
||||
build src/tags src/irpf90_entities src/irpf90.make src/IRPF90_temp/build.ninja: compile_irpf90 | make.config always
|
||||
|
||||
build src/MAIN/qmc src/MAIN/qmc_create_walkers src/MAIN/qmcchem_info: compile_src | lib/libezfio.a lib/libezfio_irp.a src/tags || src/irpf90_entities src/irpf90.make src/IRPF90_temp/build.ninja
|
||||
|
||||
# Archive
|
||||
# -------
|
||||
|
||||
build qmcchem.tar.gz: create_archive
|
||||
|
||||
# Ocaml
|
||||
# -----
|
||||
|
||||
build ocaml/qmcchem : compile_ocaml | EZFIO/Ocaml/ezfio.ml ocaml/Property.ml
|
||||
|
||||
|
||||
# Copy binaries in bin
|
||||
# --------------------
|
||||
|
||||
build bin/qmc: copy_to_bin src/MAIN/qmc
|
||||
build bin/qmcchem_info: copy_to_bin src/MAIN/qmcchem_info
|
||||
build bin/qmc_create_walkers: copy_to_bin src/MAIN/qmc_create_walkers
|
||||
build bin/qmcchem: copy_to_bin ocaml/qmcchem
|
||||
|
||||
default bin/qmc bin/qmcchem_info bin/qmc_create_walkers bin/qmcchem
|
||||
|
||||
# Clean
|
||||
# -----
|
||||
|
||||
build clean: clean
|
||||
|
16
configure.sh
16
configure.sh
@ -6,20 +6,6 @@ QMCCHEM_PATH=$PWD
|
||||
mkdir -p "${QMCCHEM_PATH}"/bin
|
||||
cd "${QMCCHEM_PATH}"/install
|
||||
mkdir -p Downloads _build
|
||||
# TODO : Check if network is up (ping)
|
||||
if [[ ! -x "${QMCCHEM_PATH}"/bin/ninja ]]
|
||||
then
|
||||
echo "Installing Ninja"
|
||||
./scripts/install_ninja.sh &> _build/ninja.log
|
||||
if [[ ! -x "${QMCCHEM_PATH}"/bin/ninja ]]
|
||||
then
|
||||
echo "Installation of Ninja failed"
|
||||
exit 1
|
||||
fi
|
||||
touch _build/ninja.ok
|
||||
fi
|
||||
touch "${QMCCHEM_PATH}"/{src,ocaml}/.ls_md5
|
||||
"${QMCCHEM_PATH}"/bin/ninja "$@"
|
||||
|
||||
cd "${QMCCHEM_PATH}"
|
||||
|
||||
@ -39,7 +25,7 @@ echo "Configuration OK."
|
||||
echo "Now, source the qmcchemrc file and build the program:"
|
||||
echo ""
|
||||
echo "source qmcchemrc"
|
||||
echo "ninja"
|
||||
echo "make"
|
||||
echo ""
|
||||
echo "====================================================================="
|
||||
|
||||
|
@ -8,12 +8,12 @@ ao_basis
|
||||
ao_expo real (ao_basis_ao_num,ao_basis_ao_prim_num_max)
|
||||
|
||||
mo_basis
|
||||
mo_tot_num integer
|
||||
mo_coef real (ao_basis_ao_num,mo_basis_mo_tot_num)
|
||||
mo_classif character (mo_basis_mo_tot_num)
|
||||
mo_energy real (mo_basis_mo_tot_num)
|
||||
mo_occ real (mo_basis_mo_tot_num)
|
||||
mo_symmetry character*(8) (mo_basis_mo_tot_num)
|
||||
mo_num integer
|
||||
mo_coef real (ao_basis_ao_num,mo_basis_mo_num)
|
||||
mo_classif character (mo_basis_mo_num)
|
||||
mo_energy real (mo_basis_mo_num)
|
||||
mo_occ real (mo_basis_mo_num)
|
||||
mo_symmetry character*(8) (mo_basis_mo_num)
|
||||
|
||||
electrons
|
||||
elec_alpha_num integer
|
||||
|
67
install/Makefile
Normal file
67
install/Makefile
Normal file
@ -0,0 +1,67 @@
|
||||
default_target: all
|
||||
|
||||
Downloads/irpf90.tar.gz:
|
||||
wget --no-check-certificate \
|
||||
"https://gitlab.com/scemama/irpf90/-/archive/v1.7.2/irpf90-v1.7.2.tar.gz" \
|
||||
-O $@.tmp -o /dev/null && mv $@.tmp $@
|
||||
|
||||
Downloads/ezfio.tar.gz:
|
||||
wget --no-check-certificate \
|
||||
"https://gitlab.com/scemama/EZFIO/-/archive/master/EZFIO-master.tar.gz" \
|
||||
-O $@.tmp -o /dev/null && mv $@.tmp $@
|
||||
|
||||
Downloads/zmq.tar.gz:
|
||||
wget --no-check-certificate \
|
||||
"http://github.com/zeromq/libzmq/releases/download/v4.2.5/zeromq-4.2.5.tar.gz" \
|
||||
-O $@.tmp -o /dev/null && mv $@.tmp $@
|
||||
|
||||
Downloads/f77_zmq.tar.gz:
|
||||
wget --no-check-certificate \
|
||||
"https://github.com/scemama/f77_zmq/archive/v4.2.5.tar.gz" \
|
||||
-O $@.tmp -o /dev/null && mv $@.tmp $@
|
||||
|
||||
Downloads/opam_installer.sh:
|
||||
wget --no-check-certificate \
|
||||
"https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh" \
|
||||
-O $@.tmp -o /dev/null && mv $@.tmp $@
|
||||
|
||||
_build/irpf90.ok ../bin/irpman ../bin/irpf90: Downloads/irpf90.tar.gz
|
||||
export target=irpf90 ; \
|
||||
./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
|
||||
touch _build/$${target}.ok || cat _build/$${target}.log
|
||||
|
||||
|
||||
_build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h: Downloads/zmq.tar.gz
|
||||
export target=zmq ; \
|
||||
./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
|
||||
touch _build/$${target}.ok || cat _build/$${target}.log
|
||||
|
||||
_build/ezfio.ok: Downloads/ezfio.tar.gz
|
||||
export target=ezfio ; \
|
||||
./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
|
||||
touch _build/$${target}.ok || cat _build/$${target}.log
|
||||
|
||||
_build/f77_zmq.ok ../src/ZMQ/f77_zmq.h ../lib/libf77zmq.a ../lib/libf77zmq.so: Downloads/f77_zmq.tar.gz _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h
|
||||
export target=f77_zmq ; \
|
||||
./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
|
||||
touch _build/$${target}.ok || cat _build/$${target}.log
|
||||
|
||||
_build/qmcchemrc.ok ../qmcchemrc: _build/irpf90.ok ../bin/irpman ../bin/irpf90 _build/ezfio.ok
|
||||
export target=qmcchemrc; \
|
||||
./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
|
||||
touch _build/$${target}.ok || cat _build/$${target}.log
|
||||
|
||||
_build/ocaml.ok ../bin/opam: Downloads/opam_installer.sh _build/qmcchemrc.ok ../qmcchemrc
|
||||
export target=ocaml; \
|
||||
./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
|
||||
touch _build/$${target}.ok || cat _build/$${target}.log
|
||||
|
||||
_build/ocaml_zmq.ok: ../bin/opam ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h _build/ocaml.ok _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h
|
||||
export target=ocaml_zmq; \
|
||||
./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
|
||||
touch _build/$${target}.ok || cat _build/$${target}.log
|
||||
|
||||
|
||||
|
||||
all: _build/ocaml_zmq.ok _build/ocaml.ok ../bin/opam _build/qmcchemrc.ok ../qmcchemrc _build/f77_zmq.ok ../src/ZMQ/f77_zmq.h ../lib/libf77zmq.a ../lib/libf77zmq.so _build/ezfio.ok _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h _build/irpf90.ok ../bin/irpman ../bin/irpf90
|
||||
|
@ -1,75 +0,0 @@
|
||||
# This script should be run in the install dircetory
|
||||
|
||||
# URLs
|
||||
######
|
||||
|
||||
URL_OPAM ="https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh"
|
||||
URL_IRPF90="https://gitlab.com/scemama/irpf90/-/archive/v1.7.2/irpf90-v1.7.2.tar.gz"
|
||||
URL_EZFIO ="https://gitlab.com/scemama/EZFIO/-/archive/master/EZFIO-master.tar.gz"
|
||||
|
||||
URL_ZMQ ="http://github.com/zeromq/libzmq/releases/download/v4.2.5/zeromq-4.2.5.tar.gz"
|
||||
URL_F77ZMQ="https://github.com/scemama/f77_zmq/archive/v4.2.5.tar.gz"
|
||||
|
||||
# Rules
|
||||
#######
|
||||
|
||||
rule download
|
||||
command = [ -e ${out} ] || (wget --no-check-certificate ${url} -O ${out}.tmp -o /dev/null && mv ${out}.tmp ${out})
|
||||
description = Downloading ${descr}
|
||||
|
||||
rule install
|
||||
command = ./scripts/install_${target}.sh > _build/${target}.log 2>&1 && touch _build/${target}.ok || cat _build/${target}.log
|
||||
description = Installing ${descr} | tail -f install/_build/${target}.log
|
||||
|
||||
|
||||
# Builds
|
||||
########
|
||||
|
||||
build Downloads/irpf90.tar.gz: download
|
||||
url = ${URL_IRPF90}
|
||||
descr = IRPF90 code generator
|
||||
|
||||
build Downloads/ezfio.tar.gz: download
|
||||
url = ${URL_EZFIO}
|
||||
descr = EZFIO I/O library generator
|
||||
|
||||
build Downloads/zmq.tar.gz: download
|
||||
url = ${URL_ZMQ}
|
||||
descr = ZeroMQ communication library
|
||||
|
||||
build Downloads/f77_zmq.tar.gz: download
|
||||
url = ${URL_F77ZMQ}
|
||||
descr = Fortran ZeroMQ interface
|
||||
|
||||
build Downloads/opam_installer.sh: download
|
||||
url = ${URL_OPAM}
|
||||
descr = OCaml OPAM installer
|
||||
|
||||
build _build/irpf90.ok ../bin/irpman ../bin/irpf90: install | Downloads/irpf90.tar.gz
|
||||
target = irpf90
|
||||
descr = IRPF90
|
||||
|
||||
build _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h: install | Downloads/zmq.tar.gz
|
||||
target = zmq
|
||||
descr = ZeroMQ
|
||||
|
||||
build _build/ezfio.ok: install | Downloads/ezfio.tar.gz _build/irpf90.ok ../bin/irpman ../bin/irpf90
|
||||
target = ezfio
|
||||
descr = EZFIO
|
||||
|
||||
build _build/f77_zmq.ok ../src/ZMQ/f77_zmq.h ../lib/libf77zmq.a ../lib/libf77zmq.so: install | Downloads/f77_zmq.tar.gz _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h
|
||||
target = f77_zmq
|
||||
descr = Fortran ZeroMQ interface
|
||||
|
||||
build _build/qmcchemrc.ok ../qmcchemrc: install | _build/irpf90.ok ../bin/irpman ../bin/irpf90 _build/ezfio.ok
|
||||
target = qmcchemrc
|
||||
description = QMC=Chem environment variables
|
||||
|
||||
build _build/ocaml.ok ../bin/opam: install | Downloads/opam_installer.sh _build/qmcchemrc.ok ../qmcchemrc
|
||||
target = ocaml
|
||||
descr = OCaml compiler
|
||||
|
||||
build _build/ocaml_zmq.ok: install | ../bin/opam ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h _build/ocaml.ok _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h
|
||||
target = ocaml_zmq
|
||||
descr = OCaml ZeroMQ interface
|
||||
|
@ -1,27 +0,0 @@
|
||||
#!/bin/bash -x
|
||||
|
||||
set -u
|
||||
set -e
|
||||
|
||||
TARGET=ninja
|
||||
URL="https://github.com/martine/ninja/archive/v1.5.3.tar.gz"
|
||||
|
||||
function _install()
|
||||
{
|
||||
cd .. ; QMCCHEM_PATH="$PWD" ; cd -
|
||||
set -e
|
||||
set -u
|
||||
cd "${BUILD}"
|
||||
./configure.py --bootstrap
|
||||
cd -
|
||||
mv "${BUILD}/ninja" "${QMCCHEM_PATH}"/bin/
|
||||
return 0
|
||||
}
|
||||
|
||||
if [[ ! -f "Downloads/${TARGET}.tar.gz" ]]
|
||||
then
|
||||
wget --no-check-certificate ${URL} -O "Downloads/${TARGET}.tar.gz.tmp"
|
||||
mv "Downloads/${TARGET}.tar.gz"{.tmp,}
|
||||
fi
|
||||
source scripts/build.sh
|
||||
|
@ -6,13 +6,12 @@ CPU_TYPE="-mavx"
|
||||
|
||||
## FORTRAN compiler
|
||||
FC="gfortran -ffree-line-length-none"
|
||||
NINJA="ninja"
|
||||
FCFLAGS="-O2 -g ${CPU_TYPE}"
|
||||
LIB="-lblas -llapack"
|
||||
LIB="-lblas -llapack -lpthread"
|
||||
|
||||
## IRPF90
|
||||
IRPF90="${QMCCHEM_PATH}/bin/irpf90"
|
||||
IRPF90_FLAGS="--align=16"
|
||||
|
||||
export FC NINJA FCFLAGS LIB IRPF90 IRPF90_FLAGS
|
||||
export FC FCFLAGS LIB IRPF90 IRPF90_FLAGS
|
||||
|
||||
|
@ -10,13 +10,12 @@ ALIGN="32"
|
||||
|
||||
## FORTRAN compiler
|
||||
FC="ifort"
|
||||
NINJA="ninja"
|
||||
FCFLAGS="-O2 -g -ip -ftz -finline ${CPU_TYPE}" #-traceback
|
||||
LIB="-mkl=sequential"
|
||||
|
||||
## IRPF90
|
||||
IRPF90="${QMCCHEM_PATH}/bin/irpf90"
|
||||
IRPF90_FLAGS="--align=${ALIGN} ${IRPF90_FLAGS}"
|
||||
IRPF90_FLAGS="--align=${ALIGN}"
|
||||
|
||||
export FC NINJA FCFLAGS LIB IRPF90 IRPF90_FLAGS
|
||||
export FC FCFLAGS LIB IRPF90 IRPF90_FLAGS
|
||||
|
||||
|
3
ocaml/.gitignore
vendored
3
ocaml/.gitignore
vendored
@ -5,9 +5,6 @@
|
||||
ezfio.ml
|
||||
Qptypes.ml
|
||||
.ls_md5
|
||||
.ninja_deps
|
||||
.ninja_log
|
||||
generated.ninja
|
||||
qmcchem
|
||||
qptypes_generator
|
||||
Property.ml
|
||||
|
@ -1,3 +1,3 @@
|
||||
PKG core cryptokit str zmq
|
||||
PKG cryptokit str zmq
|
||||
S .
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
open Core
|
||||
open Qptypes
|
||||
|
||||
type t =
|
||||
@ -6,7 +5,7 @@ type t =
|
||||
value : Sample.t ;
|
||||
weight : Weight.t ;
|
||||
compute_node : Compute_node.t ;
|
||||
pid : Pid.t ;
|
||||
pid : int ;
|
||||
block_id : Block_id.t ;
|
||||
}
|
||||
|
||||
@ -23,17 +22,17 @@ let of_string s =
|
||||
match lst with
|
||||
| b :: pid :: c:: p :: w :: v :: [] -> Some
|
||||
{ property = Property.of_string p ;
|
||||
value = Sample.of_float (Float.of_string v) ;
|
||||
weight = Weight.of_float (Float.of_string w) ;
|
||||
value = Sample.of_float (float_of_string v) ;
|
||||
weight = Weight.of_float (float_of_string w) ;
|
||||
compute_node = Compute_node.of_string c;
|
||||
pid = Pid.of_string pid;
|
||||
block_id = Block_id.of_int (Int.of_string b) ;
|
||||
pid = int_of_string pid;
|
||||
block_id = Block_id.of_int (int_of_string b) ;
|
||||
}
|
||||
| b :: pid :: c:: p :: w :: v ->
|
||||
let v =
|
||||
List.rev v
|
||||
|> Array.of_list
|
||||
|> Array.map ~f:Float.of_string
|
||||
|> Array.map float_of_string
|
||||
in
|
||||
let dim =
|
||||
Array.length v
|
||||
@ -41,10 +40,10 @@ let of_string s =
|
||||
Some
|
||||
{ property = Property.of_string p ;
|
||||
value = Sample.of_float_array ~dim v ;
|
||||
weight = Weight.of_float (Float.of_string w) ;
|
||||
weight = Weight.of_float (float_of_string w) ;
|
||||
compute_node = Compute_node.of_string c;
|
||||
pid = Pid.of_string pid;
|
||||
block_id = Block_id.of_int (Int.of_string b) ;
|
||||
pid = int_of_string pid;
|
||||
block_id = Block_id.of_int (int_of_string b) ;
|
||||
}
|
||||
| _ -> None
|
||||
with
|
||||
@ -55,10 +54,10 @@ let of_string s =
|
||||
let to_string b =
|
||||
Printf.sprintf "%s %s # %s %s %s %d"
|
||||
(Sample.to_string b.value )
|
||||
(Weight.to_float b.weight |> Float.to_string)
|
||||
(Weight.to_float b.weight |> string_of_float)
|
||||
(Property.to_string b.property)
|
||||
(Compute_node.to_string b.compute_node)
|
||||
(Pid.to_string b.pid)
|
||||
(string_of_int b.pid)
|
||||
(Block_id.to_int b.block_id)
|
||||
|
||||
|
||||
@ -70,8 +69,11 @@ let dir_name = lazy(
|
||||
let md5 =
|
||||
QmcMd5.hash ()
|
||||
in
|
||||
List.fold_right ~init:"" ~f:Filename.concat
|
||||
[ ezfio_filename ; "blocks" ; md5 ; Filename.dir_sep ]
|
||||
let d = Filename.concat ezfio_filename "blocks" in
|
||||
if not ( Sys.file_exists d ) then
|
||||
Unix.mkdir d 0o755;
|
||||
List.fold_right Filename.concat
|
||||
[ ezfio_filename ; "blocks" ; md5 ; Filename.dir_sep ] ""
|
||||
)
|
||||
|
||||
|
||||
@ -87,29 +89,31 @@ let update_raw_data ?(locked=true) () =
|
||||
in
|
||||
let files =
|
||||
let result =
|
||||
match Sys.is_directory dir_name with
|
||||
| `Yes ->
|
||||
if Sys.file_exists dir_name && Sys.is_directory dir_name then
|
||||
begin
|
||||
Sys.readdir dir_name
|
||||
|> Array.map ~f:(fun x -> dir_name^x)
|
||||
|> Array.map (fun x -> dir_name^x)
|
||||
|> Array.to_list
|
||||
end
|
||||
| _ -> []
|
||||
else []
|
||||
in
|
||||
if locked then
|
||||
result
|
||||
else
|
||||
List.filter result ~f:(fun x ->
|
||||
match String.substr_index ~pattern:"locked" x with
|
||||
| Some x -> false
|
||||
| None -> true
|
||||
)
|
||||
List.filter (fun x ->
|
||||
try
|
||||
let _ =
|
||||
Str.search_backward (Str.regexp "locked") x ((String.length x) - 1)
|
||||
in false
|
||||
with
|
||||
| Not_found -> true
|
||||
) result
|
||||
in
|
||||
|
||||
let rec transform new_list = function
|
||||
| [] -> new_list
|
||||
| head :: tail ->
|
||||
let head = String.strip head in
|
||||
let head = String.trim head in
|
||||
let item = of_string head in
|
||||
match item with
|
||||
| None -> transform new_list tail
|
||||
@ -117,13 +121,18 @@ let update_raw_data ?(locked=true) () =
|
||||
in
|
||||
|
||||
let result =
|
||||
List.map files ~f:(fun filename ->
|
||||
In_channel.with_file filename ~f:(fun in_channel ->
|
||||
In_channel.input_all in_channel)
|
||||
)
|
||||
|> String.concat
|
||||
|> String.split_lines
|
||||
|> List.rev
|
||||
let rec aux ic accu =
|
||||
try
|
||||
aux ic ( (input_line ic)::accu )
|
||||
with
|
||||
| End_of_file -> List.rev accu
|
||||
in
|
||||
List.map (fun filename ->
|
||||
let ic = open_in filename in
|
||||
let result = aux ic [] in
|
||||
close_in ic;
|
||||
result ) files
|
||||
|> List.concat
|
||||
|> transform []
|
||||
in
|
||||
result
|
||||
@ -142,9 +151,11 @@ let raw_data ?(locked=true) () =
|
||||
|
||||
|
||||
let properties = lazy (
|
||||
let set = Set.Poly.empty in
|
||||
List.fold (raw_data ()) ~init:set ~f:(fun s x -> Set.add s x.property)
|
||||
|> Set.to_list
|
||||
let h = Hashtbl.create 63 in
|
||||
List.iter (fun x ->
|
||||
Hashtbl.replace h (Property.to_string x.property) x.property)
|
||||
(raw_data ());
|
||||
Hashtbl.fold (fun k v a -> v :: a) h []
|
||||
)
|
||||
|
||||
|
||||
|
218
ocaml/Command_line.ml
Normal file
218
ocaml/Command_line.ml
Normal file
@ -0,0 +1,218 @@
|
||||
type short_opt = char
|
||||
type long_opt = string
|
||||
type optional = Mandatory | Optional
|
||||
type documentation = string
|
||||
type argument = With_arg of string | Without_arg | With_opt_arg of string
|
||||
|
||||
type description = {
|
||||
short: short_opt ;
|
||||
long : long_opt ;
|
||||
opt : optional ;
|
||||
doc : documentation ;
|
||||
arg : argument ;
|
||||
}
|
||||
|
||||
(* Mutable variables *)
|
||||
let anon_args = ref []
|
||||
and header_doc = ref ""
|
||||
and description_doc = ref ""
|
||||
and footer_doc = ref ""
|
||||
and specs = ref []
|
||||
|
||||
let reset () =
|
||||
anon_args := [];
|
||||
header_doc := "";
|
||||
description_doc := "";
|
||||
footer_doc := "";
|
||||
specs := []
|
||||
|
||||
(* End mutable variables *)
|
||||
|
||||
let set_header_doc s = header_doc := s
|
||||
let set_description_doc s = description_doc := s
|
||||
let set_footer_doc s = footer_doc := s
|
||||
|
||||
(* Hash table containing all the options *)
|
||||
let dict = Hashtbl.create 67
|
||||
|
||||
let get_bool x = Hashtbl.mem dict x
|
||||
|
||||
let show_help () = get_bool "help"
|
||||
|
||||
let get x =
|
||||
try Some (Hashtbl.find dict x)
|
||||
with Not_found -> None
|
||||
|
||||
let anonymous name opt doc =
|
||||
{ short=' ' ; long=name; opt; doc; arg=Without_arg; }
|
||||
|
||||
let output_text t =
|
||||
Format.printf "@[<v 0>";
|
||||
begin
|
||||
match Str.split (Str.regexp "\n") t with
|
||||
| x :: [] -> Format.printf "@[<hov 0>";
|
||||
Str.split (Str.regexp " ") x
|
||||
|> List.iter (fun y -> Format.printf "@[%s@]@ " y) ;
|
||||
Format.printf "@]"
|
||||
| t -> List.iter (fun x ->
|
||||
Format.printf "@[<hov 0>";
|
||||
Str.split (Str.regexp " ") x
|
||||
|> List.iter (fun y -> Format.printf "@[%s@]@ " y) ;
|
||||
Format.printf "@]@;") t
|
||||
end;
|
||||
Format.printf "@]"
|
||||
;;
|
||||
|
||||
|
||||
let output_short x =
|
||||
match x.short, x.opt, x.arg with
|
||||
| ' ', Mandatory, _ -> Format.printf "@[%s@]" x.long
|
||||
| ' ', Optional , _ -> Format.printf "@[[%s]@]" x.long
|
||||
| _ , Mandatory, Without_arg -> Format.printf "@[-%c@]" x.short
|
||||
| _ , Optional , Without_arg -> Format.printf "@[[-%c]@]" x.short
|
||||
| _ , Mandatory, With_arg arg -> Format.printf "@[-%c %s@]" x.short arg
|
||||
| _ , Optional , With_arg arg -> Format.printf "@[[-%c %s]@]" x.short arg
|
||||
| _ , Mandatory, With_opt_arg arg -> Format.printf "@[-%c [%s]@]" x.short arg
|
||||
| _ , Optional , With_opt_arg arg -> Format.printf "@[[-%c [%s]]@]" x.short arg
|
||||
|
||||
|
||||
let output_long max_width x =
|
||||
let arg =
|
||||
match x.short, x.arg with
|
||||
| ' ' , _ -> x.long
|
||||
| _ , Without_arg -> x.long
|
||||
| _ , With_arg arg -> Printf.sprintf "%s=%s" x.long arg
|
||||
| _ , With_opt_arg arg -> Printf.sprintf "%s[=%s]" x.long arg
|
||||
in
|
||||
let long =
|
||||
let l = String.length arg in
|
||||
arg^(String.make (max_width-l) ' ')
|
||||
in
|
||||
Format.printf "@[<v 0>";
|
||||
begin
|
||||
match x.short with
|
||||
| ' ' -> Format.printf "@[%s @]" long
|
||||
| short -> Format.printf "@[-%c --%s @]" short long
|
||||
end;
|
||||
Format.printf "@]";
|
||||
output_text x.doc
|
||||
|
||||
|
||||
let help () =
|
||||
|
||||
(* Print the header *)
|
||||
output_text !header_doc;
|
||||
Format.printf "@.@.";
|
||||
|
||||
(* Find the anonymous arguments *)
|
||||
let anon =
|
||||
List.filter (fun x -> x.short = ' ') !specs
|
||||
in
|
||||
|
||||
(* Find the options *)
|
||||
let options =
|
||||
List.filter (fun x -> x.short <> ' ') !specs
|
||||
|> List.sort (fun x y -> Char.compare x.short y.short)
|
||||
in
|
||||
|
||||
(* Find column lengths *)
|
||||
let max_width =
|
||||
List.map (fun x ->
|
||||
( match x.arg with
|
||||
| Without_arg -> String.length x.long
|
||||
| With_arg arg -> String.length x.long + String.length arg
|
||||
| With_opt_arg arg -> String.length x.long + String.length arg + 2
|
||||
)
|
||||
+ ( if x.opt = Optional then 2 else 0)
|
||||
) !specs
|
||||
|> List.fold_left max 0
|
||||
in
|
||||
|
||||
|
||||
(* Print usage *)
|
||||
Format.printf "@[<v>@[<v 2>Usage:@,@,@[<hov 4>@[%s@]" Sys.argv.(0);
|
||||
List.iter (fun x -> Format.printf "@ "; output_short x) options;
|
||||
Format.printf "@ @[[--]@]";
|
||||
List.iter (fun x -> Format.printf "@ "; output_short x;) anon;
|
||||
Format.printf "@]@,@]@,";
|
||||
|
||||
|
||||
(* Print arguments and doc *)
|
||||
Format.printf "@[<v 2>Arguments:@,";
|
||||
Format.printf "@[<v 0>" ;
|
||||
List.iter (fun x -> Format.printf "@ "; output_long max_width x) anon;
|
||||
Format.printf "@]@,@]@,";
|
||||
|
||||
|
||||
(* Print options and doc *)
|
||||
Format.printf "@[<v 2>Options:@,";
|
||||
|
||||
Format.printf "@[<v 0>" ;
|
||||
List.iter (fun x -> Format.printf "@ "; output_long max_width x) options;
|
||||
Format.printf "@]@,@]@,";
|
||||
|
||||
|
||||
(* Print footer *)
|
||||
if !description_doc <> "" then
|
||||
begin
|
||||
Format.printf "@[<v 2>Description:@,@,";
|
||||
output_text !description_doc;
|
||||
Format.printf "@,"
|
||||
end;
|
||||
|
||||
(* Print footer *)
|
||||
output_text !footer_doc;
|
||||
Format.printf "@."
|
||||
|
||||
|
||||
|
||||
let set_specs ?(no_help=false) specs_in =
|
||||
specs := { short='h' ;
|
||||
long ="help" ;
|
||||
doc ="Prints the help message." ;
|
||||
arg =Without_arg ;
|
||||
opt =Optional ;
|
||||
} :: specs_in;
|
||||
|
||||
let cmd_specs =
|
||||
List.filter (fun x -> x.short != ' ') !specs
|
||||
|> List.map (fun { short ; long ; opt ; doc ; arg } ->
|
||||
match arg with
|
||||
| With_arg _ ->
|
||||
(short, long, None, Some (fun x -> Hashtbl.replace dict long x) )
|
||||
| Without_arg ->
|
||||
(short, long, Some (fun () -> Hashtbl.replace dict long ""), None)
|
||||
| With_opt_arg _ ->
|
||||
(short, long, Some (fun () -> Hashtbl.replace dict long ""),
|
||||
Some (fun x -> Hashtbl.replace dict long x) )
|
||||
)
|
||||
in
|
||||
|
||||
let cmdline =
|
||||
Sys.argv
|
||||
|> Array.to_list
|
||||
|> List.filter (fun x -> x <> "")
|
||||
|> Array.of_list
|
||||
in
|
||||
Getopt.parse cmd_specs (fun x -> anon_args := !anon_args @ [x])
|
||||
cmdline 1 (Array.length cmdline -1);
|
||||
|
||||
|
||||
if not no_help && (show_help ()) then
|
||||
(help () ; exit 0);
|
||||
|
||||
|
||||
(* Check that all mandatory arguments are set *)
|
||||
List.filter (fun x -> x.short <> ' ' && x.opt = Mandatory) !specs
|
||||
|> List.iter (fun x ->
|
||||
match get x.long with
|
||||
| Some _ -> ()
|
||||
| None -> failwith ("Error: --"^x.long^" option is missing.")
|
||||
)
|
||||
;;
|
||||
|
||||
|
||||
let anon_args () = !anon_args
|
||||
|
||||
|
||||
|
129
ocaml/Command_line.mli
Normal file
129
ocaml/Command_line.mli
Normal file
@ -0,0 +1,129 @@
|
||||
(** Handles command-line arguments, using getopt.
|
||||
|
||||
Example:
|
||||
|
||||
let () =
|
||||
|
||||
(* Command-line specs *)
|
||||
let open Command_line in
|
||||
begin
|
||||
set_header_doc (Sys.argv.(0) ^ " - quantum_package command");
|
||||
set_description_doc
|
||||
"Opens a text editor to edit the parameters of an EZFIO directory.";
|
||||
|
||||
[ { short='c'; long="check"; opt=Optional;
|
||||
doc="Checks the input data";
|
||||
arg=Without_arg; };
|
||||
|
||||
{ short='n'; long="ndet"; opt=Optional;
|
||||
doc="Truncate the wavefunction to the target number of determinants";
|
||||
arg=With_arg "<int>"; };
|
||||
|
||||
{ short='s'; long="state"; opt=Optional;
|
||||
doc="Extract selected states, for example \"[1,3-5]\"";
|
||||
arg=With_arg "<range>"; };
|
||||
|
||||
anonymous "EZFIO_DIR" Mandatory "EZFIO directory";
|
||||
]
|
||||
|> set_specs ;
|
||||
|
||||
end;
|
||||
|
||||
|
||||
(* Handle options *)
|
||||
let ndet =
|
||||
match Command_line.get "ndet" with
|
||||
| None -> None
|
||||
| Some s -> (try Some (int_of_string s)
|
||||
with _ -> failwith "[-n|--ndet] expects an integer")
|
||||
in
|
||||
let state =
|
||||
match Command_line.get "state" with
|
||||
| None -> None
|
||||
| Some s -> (try Some (Range.of_string s)
|
||||
with _ -> failwith "[-s|--state] expects a range")
|
||||
in
|
||||
|
||||
let c = Command_line.get_bool "check" in
|
||||
|
||||
let filename =
|
||||
match Command_line.anon_args () with
|
||||
| [x] -> x
|
||||
| _ -> (Command_line.help () ; failwith "EZFIO_DIR is missing")
|
||||
in
|
||||
|
||||
(* Run the program *)
|
||||
run c ?ndet ?state filename
|
||||
|
||||
|
||||
*)
|
||||
|
||||
|
||||
type short_opt = char
|
||||
|
||||
type long_opt = string
|
||||
|
||||
type optional = Mandatory
|
||||
| Optional
|
||||
|
||||
type documentation = string
|
||||
|
||||
type argument = With_arg of string
|
||||
| Without_arg
|
||||
| With_opt_arg of string
|
||||
|
||||
|
||||
type description =
|
||||
{
|
||||
short : short_opt;
|
||||
long : long_opt;
|
||||
opt : optional;
|
||||
doc : documentation;
|
||||
arg : argument;
|
||||
}
|
||||
|
||||
|
||||
(** Sets the header of the help message. *)
|
||||
val set_header_doc : string -> unit
|
||||
|
||||
|
||||
(** Sets the description of the help message. *)
|
||||
val set_description_doc : string -> unit
|
||||
|
||||
(** Sets the footer of the help message. *)
|
||||
val set_footer_doc : string -> unit
|
||||
|
||||
|
||||
(** Gets the value of an option. If the option is not set, returns [None]. If
|
||||
the option is set, returns Some <string>. *)
|
||||
val get : string -> string option
|
||||
|
||||
|
||||
(** Gets the value of an option with no argument. If the option is set, returns [true]. *)
|
||||
val get_bool : string -> bool
|
||||
|
||||
|
||||
(** True if the '-h' or "--help" option was found. *)
|
||||
val show_help : unit -> bool
|
||||
|
||||
|
||||
(** Creates a specification of an anonymous argument. *)
|
||||
val anonymous : long_opt -> optional -> documentation -> description
|
||||
|
||||
|
||||
(** Prints the help message *)
|
||||
val help : unit -> unit
|
||||
|
||||
|
||||
(** Sets the specification list as a list of tuples:
|
||||
( short option, long option, documentation, argument ) *)
|
||||
val set_specs : ?no_help:bool -> description list -> unit
|
||||
|
||||
|
||||
(** Returns the list of anonymous arguments *)
|
||||
val anon_args : unit -> string list
|
||||
|
||||
|
||||
(** Reset the internal state *)
|
||||
val reset : unit -> unit
|
||||
|
@ -1,6 +1,3 @@
|
||||
open Core
|
||||
|
||||
|
||||
let simulation_nucl_fitcusp_factor = lazy(
|
||||
let default =
|
||||
1.
|
||||
@ -26,7 +23,7 @@ let simulation_time_step = lazy ( 0.15 )
|
||||
let simulation_srmc_projection_time = lazy ( 1. )
|
||||
|
||||
let reset_defaults () =
|
||||
List.iter ~f:(fun x -> Sys.remove ( (Lazy.force Qputils.ezfio_filename) ^ x))
|
||||
List.iter (fun x -> Sys.remove ( (Lazy.force Qputils.ezfio_filename) ^ x))
|
||||
[ "/electrons/elec_walk_num" ;
|
||||
"/electrons/elec_walk_num_tot" ;
|
||||
"/jastrow/jast_type" ;
|
||||
|
@ -1,4 +1,3 @@
|
||||
open Core
|
||||
open Qptypes
|
||||
open Qputils
|
||||
|
||||
@ -38,13 +37,13 @@ end = struct
|
||||
|
||||
let to_string t =
|
||||
to_bool t
|
||||
|> Bool.to_string
|
||||
|> string_of_bool
|
||||
|
||||
|
||||
let of_string t =
|
||||
try
|
||||
String.lowercase t
|
||||
|> Bool.of_string
|
||||
String.lowercase_ascii t
|
||||
|> bool_of_string
|
||||
|> of_bool
|
||||
with
|
||||
| Invalid_argument msg -> failwith msg
|
||||
@ -119,12 +118,12 @@ Fit is done for r < r_c(f) where r_c(f) = (1s orbital radius) x f. Value of f"
|
||||
|
||||
let to_string t =
|
||||
to_float t
|
||||
|> Float.to_string
|
||||
|> string_of_float
|
||||
|
||||
|
||||
let of_string t =
|
||||
try
|
||||
Float.of_string t
|
||||
float_of_string t
|
||||
|> of_float
|
||||
with
|
||||
| Invalid_argument msg -> failwith msg
|
||||
@ -181,21 +180,21 @@ end = struct
|
||||
|
||||
let to_string t =
|
||||
to_int t
|
||||
|> Int.to_string
|
||||
|> string_of_int
|
||||
|
||||
|
||||
let of_string t =
|
||||
Int.of_string t
|
||||
int_of_string t
|
||||
|> of_int
|
||||
|
||||
|
||||
let to_float t =
|
||||
to_int t
|
||||
|> Float.of_int
|
||||
|> float_of_int
|
||||
|
||||
|
||||
let of_float t =
|
||||
Int.of_float t
|
||||
int_of_float t
|
||||
|> of_int
|
||||
|
||||
|
||||
@ -248,11 +247,11 @@ end = struct
|
||||
|
||||
let to_string t =
|
||||
to_int t
|
||||
|> Int.to_string
|
||||
|> string_of_int
|
||||
|
||||
|
||||
let of_string t =
|
||||
Int.of_string t
|
||||
int_of_string t
|
||||
|> of_int
|
||||
|
||||
|
||||
@ -305,11 +304,11 @@ end = struct
|
||||
|
||||
let to_string t =
|
||||
to_int t
|
||||
|> Int.to_string
|
||||
|> string_of_int
|
||||
|
||||
|
||||
let of_string t =
|
||||
Int.of_string t
|
||||
int_of_string t
|
||||
|> of_int
|
||||
|
||||
|
||||
@ -364,21 +363,21 @@ end = struct
|
||||
|
||||
let to_string t =
|
||||
to_int t
|
||||
|> Int.to_string
|
||||
|> string_of_int
|
||||
|
||||
|
||||
let of_string t =
|
||||
Int.of_string t
|
||||
int_of_string t
|
||||
|> of_int
|
||||
|
||||
|
||||
let to_float t =
|
||||
to_int t
|
||||
|> Float.of_int
|
||||
|> float_of_int
|
||||
|
||||
|
||||
let of_float t =
|
||||
Int.of_float t
|
||||
int_of_float t
|
||||
|> of_int
|
||||
|
||||
end
|
||||
@ -456,7 +455,7 @@ end = struct
|
||||
let doc = "Sampling algorithm : [ Langevin | Brownian ]"
|
||||
|
||||
let of_string s =
|
||||
match String.capitalize (String.strip s) with
|
||||
match String.capitalize_ascii (String.trim s) with
|
||||
| "Langevin" -> Langevin
|
||||
| "Brownian" -> Brownian
|
||||
| x -> failwith ("Sampling should be [ Brownian | Langevin ], not "^x^".")
|
||||
@ -536,13 +535,13 @@ end = struct
|
||||
|
||||
|
||||
let of_string x =
|
||||
Float.of_string x
|
||||
float_of_string x
|
||||
|> of_float
|
||||
|
||||
|
||||
let to_string x =
|
||||
to_float x
|
||||
|> Float.to_string
|
||||
|> string_of_float
|
||||
|
||||
|
||||
end
|
||||
@ -593,13 +592,13 @@ end = struct
|
||||
|
||||
|
||||
let of_string x =
|
||||
Float.of_string x
|
||||
float_of_string x
|
||||
|> of_float
|
||||
|
||||
|
||||
let to_string x =
|
||||
to_float x
|
||||
|> Float.to_string
|
||||
|> string_of_float
|
||||
|
||||
|
||||
end
|
||||
@ -652,13 +651,13 @@ contribution to the norm less than t (au)"
|
||||
|
||||
|
||||
let of_string x =
|
||||
Float.of_string x
|
||||
float_of_string x
|
||||
|> of_float
|
||||
|
||||
|
||||
let to_string x =
|
||||
to_float x
|
||||
|> Float.to_string
|
||||
|> string_of_float
|
||||
|
||||
end
|
||||
|
||||
@ -708,13 +707,13 @@ end = struct
|
||||
|
||||
|
||||
let of_string x =
|
||||
Float.of_string x
|
||||
float_of_string x
|
||||
|> of_float
|
||||
|
||||
|
||||
let to_string x =
|
||||
to_float x
|
||||
|> Float.to_string
|
||||
|> string_of_float
|
||||
|
||||
end
|
||||
|
||||
@ -764,13 +763,13 @@ end = struct
|
||||
|
||||
|
||||
let of_string x =
|
||||
Float.of_string x
|
||||
float_of_string x
|
||||
|> of_float
|
||||
|
||||
|
||||
let to_string x =
|
||||
to_float x
|
||||
|> Float.to_string
|
||||
|> string_of_float
|
||||
|
||||
end
|
||||
|
||||
@ -789,7 +788,7 @@ end = struct
|
||||
let doc = "Type of Jastrow factor [ None | Core | Simple ]"
|
||||
|
||||
let of_string s =
|
||||
match String.capitalize (String.strip s) with
|
||||
match String.capitalize_ascii (String.trim s) with
|
||||
| "Core" -> Core
|
||||
| "Simple" -> Simple
|
||||
| "None" -> None
|
||||
@ -841,31 +840,31 @@ end = struct
|
||||
|
||||
|
||||
let read () =
|
||||
List.map Property.all ~f:(fun x -> (x, Property.calc x))
|
||||
List.map (fun x -> (x, Property.calc x)) Property.all
|
||||
|
||||
|
||||
let write l =
|
||||
List.iter l ~f:(fun (x,b) -> Property.set_calc x b)
|
||||
List.iter (fun (x,b) -> Property.set_calc x b) l
|
||||
|
||||
|
||||
let to_string l =
|
||||
List.map l ~f:(fun (x,b) ->
|
||||
List.map (fun (x,b) ->
|
||||
let ch =
|
||||
if b then "X" else " "
|
||||
in
|
||||
Printf.sprintf "(%s) %s" ch (Property.to_string x))
|
||||
|> String.concat ~sep:"\n"
|
||||
Printf.sprintf "(%s) %s" ch (Property.to_string x)) l
|
||||
|> String.concat "\n"
|
||||
|
||||
|
||||
let of_string s =
|
||||
String.split s ~on:'\n'
|
||||
|> List.map ~f:(fun x ->
|
||||
String.split_on_char '\n' s
|
||||
|> List.map (fun x ->
|
||||
let (calc,prop) =
|
||||
String.strip x
|
||||
|> String.rsplit2_exn ~on:' '
|
||||
String.trim x
|
||||
|> String_ext.rsplit2_exn ~on:' '
|
||||
in
|
||||
let prop =
|
||||
String.strip prop
|
||||
String.trim prop
|
||||
|> Property.of_string
|
||||
and calc =
|
||||
match calc with
|
||||
|
@ -1,5 +1,3 @@
|
||||
open Core
|
||||
|
||||
type t =
|
||||
| Srun
|
||||
| MPI
|
||||
@ -50,19 +48,21 @@ let create_nodefile () =
|
||||
in
|
||||
|
||||
let h =
|
||||
String.Table.create ~size:1000 ()
|
||||
Hashtbl.create 1000
|
||||
in
|
||||
|
||||
let in_channel =
|
||||
Unix.open_process_in (launcher_command^" hostname -s")
|
||||
in
|
||||
In_channel.input_lines in_channel
|
||||
|> List.map ~f:String.strip
|
||||
|> List.iter ~f:( fun host ->
|
||||
Hashtbl.change h host (function
|
||||
| Some x -> Some (x+1)
|
||||
| None -> Some 1
|
||||
)
|
||||
String_ext.input_lines in_channel
|
||||
|> List.map String.trim
|
||||
|> List.iter ( fun host ->
|
||||
let n =
|
||||
match Hashtbl.find_opt h host with
|
||||
| Some x -> x+1
|
||||
| None -> 1
|
||||
in
|
||||
Hashtbl.replace h host n
|
||||
);
|
||||
match
|
||||
Unix.close_process_in in_channel
|
||||
@ -80,9 +80,8 @@ let create_nodefile () =
|
||||
fun (node, n) ->
|
||||
Printf.sprintf "%s %d\n" node n
|
||||
in
|
||||
Hashtbl.to_alist h
|
||||
|> List.map ~f
|
||||
|> String.concat
|
||||
Hashtbl.fold (fun k v a -> (f (k,v)) :: a) h []
|
||||
|> String.concat "\n"
|
||||
|
||||
|
||||
|
||||
|
59
ocaml/Makefile
Normal file
59
ocaml/Makefile
Normal file
@ -0,0 +1,59 @@
|
||||
.NOPARALLEL:
|
||||
|
||||
# Check if QMCCHEM_PATH is defined
|
||||
ifndef QMCCHEM_PATH
|
||||
$(info -------------------- Error --------------------)
|
||||
$(info QMCCHEM_PATH undefined. Source the qmcchem.rc script)
|
||||
$(info -----------------------------------------------)
|
||||
$(error )
|
||||
endif
|
||||
|
||||
|
||||
LIBS=
|
||||
PKGS=
|
||||
OCAMLCFLAGS="-g"
|
||||
OCAMLOPTFLAGS="opt -O3 -remove-unused-arguments -rounds 16 -inline 100 -inline-max-unroll 100"
|
||||
OCAMLBUILD=ocamlbuild -j 0 -cflags $(OCAMLCFLAGS) -lflags $(OCAMLCFLAGS) -ocamlopt $(OCAMLOPTFLAGS)
|
||||
MLLFILES=$(wildcard *.mll)
|
||||
MLFILES=$(wildcard *.ml) ezfio.ml Qptypes.ml
|
||||
MLIFILES=$(wildcard *.mli)
|
||||
ALL_TESTS=$(patsubst %.ml,%.byte,$(wildcard test_*.ml))
|
||||
ALL_EXE=$(patsubst %.ml,%.native,$(wildcard qp_*.ml)) qmcchem.native
|
||||
|
||||
.PHONY: default
|
||||
|
||||
|
||||
default: $(ALL_EXE)
|
||||
|
||||
tests: $(ALL_TESTS)
|
||||
|
||||
|
||||
%.inferred.mli: $(MLFILES)
|
||||
$(OCAMLBUILD) $*.inferred.mli -use-ocamlfind $(PKGS)
|
||||
mv _build/$*.inferred.mli .
|
||||
|
||||
%.byte: $(MLFILES) $(MLIFILES)
|
||||
rm -f -- $*
|
||||
$(OCAMLBUILD) $*.byte -use-ocamlfind $(PKGS)
|
||||
ln -s $*.byte $*
|
||||
|
||||
%.native: $(MLFILES) $(MLIFILES)
|
||||
rm -f -- $*
|
||||
$(OCAMLBUILD) $*.native -use-ocamlfind $(PKGS)
|
||||
ln -s $*.native $*
|
||||
|
||||
ezfio.ml: ${QMCCHEM_PATH}/EZFIO/Ocaml/ezfio.ml
|
||||
cp ${QMCCHEM_PATH}/EZFIO/Ocaml/ezfio.ml .
|
||||
|
||||
qptypes_generator.byte: qptypes_generator.ml
|
||||
$(OCAMLBUILD) qptypes_generator.byte -use-ocamlfind
|
||||
|
||||
Qptypes.ml: qptypes_generator.byte
|
||||
./qptypes_generator.byte > Qptypes.ml
|
||||
|
||||
${QMCCHEM_PATH}/EZFIO/Ocaml/ezfio.ml:
|
||||
${MAKE) -C ${QMCCHEM_PATH}/EZFIO/
|
||||
|
||||
clean:
|
||||
rm -rf _build Qptypes.ml $(ALL_EXE) $(ALL_TESTS)
|
||||
|
149
ocaml/Md5.ml
149
ocaml/Md5.ml
@ -1,149 +0,0 @@
|
||||
open Core
|
||||
|
||||
(** Directory containing the list of input files. The directory is created is inexistant. *)
|
||||
let input_directory = lazy (
|
||||
|
||||
let ezfio_filename =
|
||||
Lazy.force Qputils.ezfio_filename
|
||||
in
|
||||
|
||||
let dirname =
|
||||
Filename.concat ezfio_filename "input"
|
||||
in
|
||||
|
||||
begin
|
||||
match ( Sys.is_directory dirname ) with
|
||||
| `No -> Unix.mkdir dirname
|
||||
| _ -> ()
|
||||
end ;
|
||||
|
||||
dirname
|
||||
)
|
||||
|
||||
|
||||
(** List of files responsible for the MD5 key of the input *)
|
||||
let files_to_track = [
|
||||
"ao_basis/ao_coef.gz" ;
|
||||
"ao_basis/ao_expo.gz" ;
|
||||
"ao_basis/ao_nucl.gz" ;
|
||||
"ao_basis/ao_num" ;
|
||||
"ao_basis/ao_power.gz" ;
|
||||
"ao_basis/ao_prim_num.gz" ;
|
||||
"electrons/elec_alpha_num" ;
|
||||
"electrons/elec_beta_num" ;
|
||||
"electrons/elec_walk_num" ;
|
||||
"jastrow/jast_type" ;
|
||||
"mo_basis/mo_coef.gz" ;
|
||||
"mo_basis/mo_tot_num" ;
|
||||
"nuclei/nucl_charge.gz" ;
|
||||
"nuclei/nucl_coord.gz" ;
|
||||
"nuclei/nucl_num" ;
|
||||
"simulation/ci_threshold" ;
|
||||
"simulation/nucl_fitcusp_factor" ;
|
||||
"simulation/jast_a_up_dn" ;
|
||||
"simulation/jast_a_up_up" ;
|
||||
"simulation/jast_b_up_dn" ;
|
||||
"simulation/jast_b_up_up" ;
|
||||
"simulation/jast_core_a1" ;
|
||||
"simulation/jast_core_a2" ;
|
||||
"simulation/jast_core_b1" ;
|
||||
"simulation/jast_core_b2" ;
|
||||
"simulation/jast_een_e_a.gz" ;
|
||||
"simulation/jast_een_e_b.gz" ;
|
||||
"simulation/jast_een_n.gz" ;
|
||||
"simulation/jast_pen.gz" ;
|
||||
"simulation/method" ;
|
||||
"simulation/time_step" ;
|
||||
"simulation/dmc_projection_time" ;
|
||||
"spindeterminants/bit_kind" ;
|
||||
"spindeterminants/n_det" ;
|
||||
"spindeterminants/n_det_alpha" ;
|
||||
"spindeterminants/n_det_beta" ;
|
||||
"spindeterminants/n_int" ;
|
||||
"spindeterminants/n_states" ;
|
||||
"spindeterminants/psi_coef_matrix_columns.gz" ;
|
||||
"spindeterminants/psi_coef_matrix_rows.gz" ;
|
||||
"spindeterminants/psi_coef_matrix_values.gz" ;
|
||||
"spindeterminants/psi_det_alpha.gz" ;
|
||||
"spindeterminants/psi_det_beta.gz" ;
|
||||
"/pseudo/do_pseudo" ;
|
||||
"/pseudo/mo_pseudo_grid.gz" ;
|
||||
"/pseudo/pseudo_dz_kl.gz";
|
||||
"/pseudo/pseudo_klocmax" ;
|
||||
"/pseudo/pseudo_n_k.gz" ;
|
||||
"/pseudo/pseudo_v_kl.gz" ;
|
||||
"/pseudo/pseudo_grid_rmax" ;
|
||||
"/pseudo/pseudo_kmax" ;
|
||||
"/pseudo/pseudo_n_kl.gz" ;
|
||||
"/pseudo/pseudo_dz_k.gz" ;
|
||||
"/pseudo/pseudo_grid_size" ;
|
||||
"/pseudo/pseudo_v_k.gz" ;
|
||||
]
|
||||
|
||||
|
||||
(** Get an MD5 ke from the content of a file. *)
|
||||
let hash_file filename =
|
||||
match Sys.is_file filename with
|
||||
| `Yes ->
|
||||
begin
|
||||
In_channel.with_file filename ~f:(fun ic ->
|
||||
Cryptokit.hash_channel (Cryptokit.Hash.md5 ()) ic
|
||||
|> Cryptokit.transform_string (Cryptokit.Hexa.encode ()) )
|
||||
end
|
||||
| _ -> ""
|
||||
|
||||
|
||||
(** Cache containing the current value of the MD5 hash. *)
|
||||
let _hash =
|
||||
ref None
|
||||
|
||||
(** Get the hash correcponding to the EZFIO file. *)
|
||||
let hash () =
|
||||
let compute_hash () =
|
||||
let ezfio_filename =
|
||||
Lazy.force Qputils.ezfio_filename
|
||||
in
|
||||
let old_md5 =
|
||||
if Ezfio.has_simulation_md5_key () then
|
||||
Ezfio.get_simulation_md5_key ()
|
||||
else
|
||||
""
|
||||
in
|
||||
let md5_string =
|
||||
files_to_track
|
||||
|> List.map ~f:(fun x -> Printf.sprintf "%s/%s" ezfio_filename x)
|
||||
|> List.map ~f:hash_file
|
||||
|> String.concat
|
||||
in
|
||||
|
||||
let new_md5 =
|
||||
md5_string
|
||||
|> Cryptokit.hash_string (Cryptokit.Hash.md5 ())
|
||||
|> Cryptokit.transform_string (Cryptokit.Hexa.encode ())
|
||||
in
|
||||
if (new_md5 <> old_md5) then
|
||||
begin
|
||||
Printf.eprintf "Info : MD5 key changed\n %s\n-> %s\n%!" old_md5 new_md5 ;
|
||||
Ezfio.set_simulation_md5_key new_md5
|
||||
end
|
||||
;
|
||||
new_md5
|
||||
in
|
||||
match (!_hash) with
|
||||
| Some key -> key
|
||||
| None ->
|
||||
begin
|
||||
let key =
|
||||
compute_hash ()
|
||||
in
|
||||
_hash := Some key ;
|
||||
key
|
||||
end
|
||||
|
||||
(** Reset the cache of the MD5 hash. *)
|
||||
let reset_hash () =
|
||||
_hash := None;
|
||||
ignore (hash ())
|
||||
|
||||
|
||||
|
@ -1,11 +1,10 @@
|
||||
open Core
|
||||
open Qptypes
|
||||
|
||||
type t =
|
||||
| Property of Block.t
|
||||
| Walkers of Compute_node.t * Pid.t * (float array) array
|
||||
| Register of Compute_node.t * Pid.t
|
||||
| Unregister of Compute_node.t * Pid.t
|
||||
| Walkers of Compute_node.t * int * (float array) array
|
||||
| Register of Compute_node.t * int
|
||||
| Unregister of Compute_node.t * int
|
||||
| Test
|
||||
| GetWalkers of Strictly_positive_int.t
|
||||
| Ezfio of string
|
||||
@ -19,45 +18,45 @@ let create m =
|
||||
let open Block in
|
||||
Property
|
||||
{ property = Property.Cpu;
|
||||
value = Sample.of_float (Float.of_string v) ;
|
||||
value = Sample.of_float (float_of_string v) ;
|
||||
weight = Weight.of_float 1.;
|
||||
compute_node = Compute_node.of_string c;
|
||||
pid = Pid.of_string pid;
|
||||
block_id = Block_id.of_int (Int.of_string b);
|
||||
pid = int_of_string pid;
|
||||
block_id = Block_id.of_int (int_of_string b);
|
||||
}
|
||||
| [ "accep" ; c ; pid ; b ; "1" ; v ] ->
|
||||
let open Block in
|
||||
Property
|
||||
{ property = Property.Accep;
|
||||
value = Sample.of_float (Float.of_string v) ;
|
||||
value = Sample.of_float (float_of_string v) ;
|
||||
weight = Weight.of_float 1.;
|
||||
compute_node = Compute_node.of_string c;
|
||||
pid = Pid.of_string pid;
|
||||
block_id = Block_id.of_int (Int.of_string b);
|
||||
pid = int_of_string pid;
|
||||
block_id = Block_id.of_int (int_of_string b);
|
||||
}
|
||||
| [ prop ; c ; pid ; b ; w ; v ] ->
|
||||
let open Block in
|
||||
Property
|
||||
{ property = Property.of_string prop;
|
||||
value = Sample.of_float (Float.of_string v);
|
||||
weight = Weight.of_float (Float.of_string w);
|
||||
value = Sample.of_float (float_of_string v);
|
||||
weight = Weight.of_float (float_of_string w);
|
||||
compute_node = Compute_node.of_string c;
|
||||
pid = Pid.of_string pid;
|
||||
block_id = Block_id.of_int (Int.of_string b);
|
||||
pid = int_of_string pid;
|
||||
block_id = Block_id.of_int (int_of_string b);
|
||||
}
|
||||
| "elec_coord" :: c :: pid :: _ :: n ::walkers ->
|
||||
begin
|
||||
let elec_num =
|
||||
Lazy.force Qputils.elec_num
|
||||
and n =
|
||||
Int.of_string n
|
||||
int_of_string n
|
||||
in
|
||||
assert (n = List.length walkers);
|
||||
let rec build_walker accu = function
|
||||
| (0,tail) ->
|
||||
let result =
|
||||
List.rev accu
|
||||
|> List.map ~f:Float.of_string
|
||||
|> List.map float_of_string
|
||||
|> Array.of_list
|
||||
in
|
||||
(result, tail)
|
||||
@ -73,11 +72,11 @@ let create m =
|
||||
in
|
||||
build (result::accu) tail
|
||||
in
|
||||
Walkers (Compute_node.of_string c, Pid.of_string pid, build [] walkers)
|
||||
Walkers (Compute_node.of_string c, int_of_string pid, build [] walkers)
|
||||
end
|
||||
| [ "get_walkers" ; n ] -> GetWalkers (n |> Int.of_string |> Strictly_positive_int.of_int)
|
||||
| [ "register" ; c ; pid ] -> Register (Compute_node.of_string c, Pid.of_string pid)
|
||||
| [ "unregister" ; c ; pid ] -> Unregister (Compute_node.of_string c, Pid.of_string pid)
|
||||
| [ "get_walkers" ; n ] -> GetWalkers (n |> int_of_string |> Strictly_positive_int.of_int)
|
||||
| [ "register" ; c ; pid ] -> Register (Compute_node.of_string c, int_of_string pid)
|
||||
| [ "unregister" ; c ; pid ] -> Unregister (Compute_node.of_string c, int_of_string pid)
|
||||
| [ "Test" ] -> Test
|
||||
| [ "Ezfio" ; ezfio_msg ] -> Ezfio ezfio_msg
|
||||
| prop :: c :: pid :: b :: d :: w :: l ->
|
||||
@ -88,22 +87,22 @@ let create m =
|
||||
assert (not (Property.is_scalar property));
|
||||
let a =
|
||||
Array.of_list l
|
||||
|> Array.map ~f:Float.of_string
|
||||
|> Array.map float_of_string
|
||||
and dim =
|
||||
Int.of_string d
|
||||
int_of_string d
|
||||
in
|
||||
assert (Array.length a = dim);
|
||||
let open Block in
|
||||
Property
|
||||
{ property = property ;
|
||||
value = Sample.of_float_array ~dim a;
|
||||
weight = Weight.of_float (Float.of_string w);
|
||||
weight = Weight.of_float (float_of_string w);
|
||||
compute_node = Compute_node.of_string c;
|
||||
pid = Pid.of_string pid;
|
||||
block_id = Block_id.of_int (Int.of_string b);
|
||||
pid = int_of_string pid;
|
||||
block_id = Block_id.of_int (int_of_string b);
|
||||
}
|
||||
end
|
||||
| l -> Error (String.concat ~sep:":" l)
|
||||
| l -> Error (String.concat ":" l)
|
||||
with
|
||||
| Assert_failure (l,_,_) -> Error l
|
||||
| _ -> Error "Unknown error"
|
||||
@ -111,14 +110,13 @@ let create m =
|
||||
|
||||
let to_string = function
|
||||
| Property b -> "Property : "^(Block.to_string b)
|
||||
| Walkers (h,p,w) -> Printf.sprintf "Walkers : %s %s : %d walkers"
|
||||
(Compute_node.to_string h) (Pid.to_string p)
|
||||
(Array.length w)
|
||||
| Walkers (h,p,w) -> Printf.sprintf "Walkers : %s %d : %d walkers"
|
||||
(Compute_node.to_string h) p (Array.length w)
|
||||
| GetWalkers n -> Printf.sprintf "GetWalkers %d" (Strictly_positive_int.to_int n)
|
||||
| Register (h,p) -> Printf.sprintf "Register : %s %s"
|
||||
(Compute_node.to_string h) (Pid.to_string p)
|
||||
| Unregister (h,p) -> Printf.sprintf "Unregister : %s %s"
|
||||
(Compute_node.to_string h) (Pid.to_string p)
|
||||
| Register (h,p) -> Printf.sprintf "Register : %s %d"
|
||||
(Compute_node.to_string h) p
|
||||
| Unregister (h,p) -> Printf.sprintf "Unregister : %s %d"
|
||||
(Compute_node.to_string h) p
|
||||
| Test -> "Test"
|
||||
| Ezfio msg -> "Ezfio "^msg
|
||||
| Error msg -> "Error "^msg
|
||||
|
@ -1,5 +1,3 @@
|
||||
open Core
|
||||
|
||||
(** Directory containing the list of input files. The directory is created is inexistant. *)
|
||||
let input_directory = lazy (
|
||||
|
||||
@ -12,9 +10,8 @@ let input_directory = lazy (
|
||||
in
|
||||
|
||||
begin
|
||||
match ( Sys.is_directory dirname ) with
|
||||
| `No -> Unix.mkdir dirname
|
||||
| _ -> ()
|
||||
if not (Sys.file_exists dirname) then
|
||||
Unix.mkdir dirname 0o777
|
||||
end ;
|
||||
|
||||
dirname
|
||||
@ -83,14 +80,17 @@ let files_to_track = [
|
||||
|
||||
(** Get an MD5 ke from the content of a file. *)
|
||||
let hash_file filename =
|
||||
match Sys.is_file filename with
|
||||
| `Yes ->
|
||||
if Sys.file_exists filename then
|
||||
begin
|
||||
In_channel.with_file filename ~f:(fun ic ->
|
||||
let ic = open_in filename in
|
||||
let result =
|
||||
Cryptokit.hash_channel (Cryptokit.Hash.md5 ()) ic
|
||||
|> Cryptokit.transform_string (Cryptokit.Hexa.encode ()) )
|
||||
|> Cryptokit.transform_string (Cryptokit.Hexa.encode ())
|
||||
in
|
||||
close_in ic;
|
||||
result
|
||||
end
|
||||
| _ -> ""
|
||||
else ""
|
||||
|
||||
|
||||
(** Cache containing the current value of the MD5 hash. *)
|
||||
@ -111,9 +111,9 @@ let hash () =
|
||||
in
|
||||
let md5_string =
|
||||
files_to_track
|
||||
|> List.map ~f:(fun x -> Printf.sprintf "%s/%s" ezfio_filename x)
|
||||
|> List.map ~f:hash_file
|
||||
|> String.concat
|
||||
|> List.map (fun x -> Printf.sprintf "%s/%s" ezfio_filename x)
|
||||
|> List.map hash_file
|
||||
|> String.concat ""
|
||||
in
|
||||
|
||||
let new_md5 =
|
||||
|
@ -1,22 +1,18 @@
|
||||
open Core
|
||||
|
||||
|
||||
(** QMC=Chem installation directory *)
|
||||
let root = lazy (
|
||||
match ( Sys.getenv "QMCCHEM_PATH" ) with
|
||||
| Some x -> x
|
||||
| None -> failwith "QMCCHEM_PATH environment variable not set"
|
||||
try Sys.getenv "QMCCHEM_PATH" with
|
||||
| Not_found -> failwith "QMCCHEM_PATH environment variable not set"
|
||||
)
|
||||
|
||||
|
||||
(* PATH environment variable as a list of strings *)
|
||||
let path = lazy (
|
||||
let p =
|
||||
match Sys.getenv "PATH" with
|
||||
| None -> failwith "PATH environment variable is not set"
|
||||
| Some p -> p
|
||||
try Sys.getenv "PATH" with
|
||||
| Not_found -> failwith "PATH environment variable is not set"
|
||||
in
|
||||
String.split ~on:':' p
|
||||
String.split_on_char ':' p
|
||||
)
|
||||
|
||||
|
||||
@ -30,9 +26,10 @@ let full_path exe =
|
||||
let fp =
|
||||
Filename.concat head exe
|
||||
in
|
||||
match (Sys.is_file fp) with
|
||||
| `Yes -> Some fp
|
||||
| _ -> in_path_rec tail
|
||||
if Sys.file_exists fp then
|
||||
Some fp
|
||||
else
|
||||
in_path_rec tail
|
||||
end
|
||||
in
|
||||
Lazy.force path
|
||||
@ -42,7 +39,7 @@ let full_path exe =
|
||||
|
||||
(* True if an executable is in the PATH *)
|
||||
let in_path x =
|
||||
match (full_path x) with
|
||||
match full_path x with
|
||||
| Some _ -> true
|
||||
| None -> false
|
||||
|
||||
@ -51,13 +48,13 @@ let has_parallel = lazy( in_path "parallel" )
|
||||
let has_mpirun = lazy( in_path "mpirun" )
|
||||
let has_srun = lazy( in_path "parallel" )
|
||||
let has_qmc = lazy( in_path "qmc" )
|
||||
let has_qmc_mic = lazy( in_path "qmc_mic" )
|
||||
|
||||
|
||||
let mpirun = lazy (
|
||||
match Sys.getenv "QMCCHEM_MPIRUN" with
|
||||
| None -> "mpirun"
|
||||
| Some p -> p
|
||||
try
|
||||
Sys.getenv "QMCCHEM_MPIRUN"
|
||||
with
|
||||
| Not_found -> "mpirun"
|
||||
)
|
||||
|
||||
let qmcchem = lazy(
|
||||
@ -69,9 +66,7 @@ and qmc = lazy(
|
||||
and qmcchem_info = lazy(
|
||||
Filename.concat (Lazy.force root) "bin/qmcchem_info"
|
||||
)
|
||||
and qmc_mic = lazy(
|
||||
Filename.concat (Lazy.force root) "bin/qmc_mic"
|
||||
)
|
||||
|
||||
and qmc_create_walkers = lazy(
|
||||
Filename.concat (Lazy.force root) "bin/qmc_create_walkers"
|
||||
)
|
||||
@ -87,28 +82,35 @@ let hostname = lazy (
|
||||
)
|
||||
|
||||
|
||||
external get_ipv4_address_for_interface : string -> string =
|
||||
"get_ipv4_address_for_interface"
|
||||
|
||||
|
||||
let ip_address = lazy (
|
||||
match Sys.getenv "QMCCHEM_NIC" with
|
||||
let interface =
|
||||
try Some (Sys.getenv "QMCCHEM_NIC")
|
||||
with Not_found -> None
|
||||
in
|
||||
match interface with
|
||||
| None ->
|
||||
begin
|
||||
try
|
||||
let host =
|
||||
Lazy.force hostname
|
||||
|> Unix.Inet_addr.of_string_or_getbyname
|
||||
|> Unix.Inet_addr.to_string
|
||||
|> Unix.gethostbyname
|
||||
in
|
||||
Unix.string_of_inet_addr host.h_addr_list.(0);
|
||||
with
|
||||
| Unix.Unix_error _ ->
|
||||
failwith "Unable to find IP address from host name."
|
||||
end
|
||||
| Some interface ->
|
||||
begin
|
||||
try
|
||||
ok_exn Linux_ext.get_ipv4_address_for_interface interface
|
||||
with
|
||||
| Unix.Unix_error _ ->
|
||||
Lazy.force hostname
|
||||
|> Unix.Inet_addr.of_string_or_getbyname
|
||||
|> Unix.Inet_addr.to_string
|
||||
end
|
||||
let result = get_ipv4_address_for_interface interface in
|
||||
if String.sub result 0 5 = "error" then
|
||||
Printf.sprintf "Unable to use network interface %s" interface
|
||||
|> failwith
|
||||
else
|
||||
result
|
||||
)
|
||||
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
open Core
|
||||
open Qptypes
|
||||
|
||||
(** Data server of QMC=Chem.
|
||||
@ -35,20 +34,26 @@ let run ?(daemon=true) ezfio_filename =
|
||||
if ( not(Ezfio.has_electrons_elec_coord_pool ()) ) then
|
||||
begin
|
||||
Printf.printf "Generating initial walkers...\n%!";
|
||||
Unix.fork_exec ~prog:(Lazy.force Qmcchem_config.qmc_create_walkers)
|
||||
~argv:["qmc_create_walkers" ; ezfio_filename] ()
|
||||
|> Unix.waitpid_exn ;
|
||||
match Unix.fork () with
|
||||
| 0 ->
|
||||
Unix.execvp
|
||||
(Lazy.force Qmcchem_config.qmc_create_walkers)
|
||||
[|"qmc_create_walkers" ; ezfio_filename|]
|
||||
| pid ->
|
||||
begin
|
||||
ignore @@ Unix.waitpid [] pid;
|
||||
Printf.printf "Initial walkers ready\n%!"
|
||||
end ;
|
||||
end
|
||||
end
|
||||
in
|
||||
|
||||
|
||||
(** Measures the time difference between [t0] and [Time.now ()] *)
|
||||
(** Measures the time difference between [t0] and [Unix.gettimeofday ()] *)
|
||||
let delta_t t0 =
|
||||
let t1 =
|
||||
Time.now ()
|
||||
Unix.gettimeofday ()
|
||||
in
|
||||
Time.abs_diff t1 t0
|
||||
t1 -. t0
|
||||
in
|
||||
|
||||
(** {2 ZeroMQ initialization} *)
|
||||
@ -60,8 +65,7 @@ let run ?(daemon=true) ezfio_filename =
|
||||
|
||||
|
||||
(** Maximum size of the blocks file before compressing *)
|
||||
let max_file_size = ref (
|
||||
Byte_units.create `Kilobytes 64.)
|
||||
let max_file_size = ref ( 64 * 1024 )
|
||||
in
|
||||
|
||||
|
||||
@ -88,9 +92,9 @@ let run ?(daemon=true) ezfio_filename =
|
||||
"tcp://*:"
|
||||
in
|
||||
let result =
|
||||
List.fold [0;1;2;3] ~init:true ~f:(fun accu i ->
|
||||
List.fold_left (fun accu i ->
|
||||
let address =
|
||||
adress_prefix ^ (Int.to_string (n+i))
|
||||
adress_prefix ^ (string_of_int (n+i))
|
||||
in
|
||||
let socket =
|
||||
Zmq.Socket.create zmq_context Zmq.Socket.rep
|
||||
@ -104,7 +108,7 @@ let run ?(daemon=true) ezfio_filename =
|
||||
in
|
||||
Zmq.Socket.close socket;
|
||||
result
|
||||
)
|
||||
) true [0;1;2;3]
|
||||
in
|
||||
if (result) then
|
||||
`Available
|
||||
@ -145,8 +149,8 @@ let run ?(daemon=true) ezfio_filename =
|
||||
delta_t t0
|
||||
in
|
||||
let message =
|
||||
Printf.sprintf "%20s : %8d : %10s : %s"
|
||||
socket size text (Time.Span.to_string dt)
|
||||
Printf.sprintf "%20s : %8d : %10s : %e"
|
||||
socket size text dt
|
||||
in
|
||||
Zmq.Socket.send debug_socket message
|
||||
in
|
||||
@ -179,7 +183,7 @@ let run ?(daemon=true) ezfio_filename =
|
||||
(** Array of walkers. The size is [walk_num_tot]. *)
|
||||
let walkers_array =
|
||||
let t0 =
|
||||
Time.now ()
|
||||
Unix.gettimeofday ()
|
||||
in
|
||||
let j =
|
||||
3*elec_num + 3
|
||||
@ -190,16 +194,16 @@ let run ?(daemon=true) ezfio_filename =
|
||||
and ez =
|
||||
Ezfio.get_electrons_elec_coord_pool ()
|
||||
|> Ezfio.flattened_ezfio
|
||||
|> Array.map ~f:Float.to_string
|
||||
|> Array.map string_of_float
|
||||
in
|
||||
try
|
||||
Array.init walk_num_tot ~f:(fun i ->
|
||||
Array.sub ~pos:(j*(i mod size)) ~len:j ez)
|
||||
Array.init walk_num_tot (fun i ->
|
||||
Array.sub ez (j*(i mod size)) j )
|
||||
with
|
||||
| Invalid_argument _ ->
|
||||
failwith "Walkers file is broken."
|
||||
in
|
||||
String.concat [ "Read " ; Int.to_string (Array.length result) ;
|
||||
String.concat " " [ "Read" ; string_of_int (Array.length result) ;
|
||||
"walkers"]
|
||||
|> send_log "status" 0 t0 ;
|
||||
result
|
||||
@ -214,28 +218,28 @@ let run ?(daemon=true) ezfio_filename =
|
||||
|
||||
(** Last time when the walkers were saved to disk. *)
|
||||
let last_save_walkers =
|
||||
ref (Time.now ())
|
||||
ref (Unix.gettimeofday ())
|
||||
in
|
||||
|
||||
|
||||
(** Saves the walkers to disk. *)
|
||||
let save_walkers () =
|
||||
if (delta_t !last_save_walkers > (Time.Span.of_sec 10.) ) then
|
||||
if (delta_t !last_save_walkers > 10. ) then
|
||||
begin
|
||||
let t0 =
|
||||
Time.now ()
|
||||
Unix.gettimeofday ()
|
||||
in
|
||||
Ezfio.set_electrons_elec_coord_pool_size walk_num_tot ;
|
||||
let walkers_list =
|
||||
Array.map walkers_array ~f:Array.to_list
|
||||
Array.map Array.to_list walkers_array
|
||||
|> Array.to_list
|
||||
|> List.concat
|
||||
|> List.map ~f:Float.of_string
|
||||
|> List.map float_of_string
|
||||
in
|
||||
Ezfio.set_electrons_elec_coord_pool (Ezfio.ezfio_array_of_list
|
||||
~rank:3 ~dim:[| elec_num+1 ; 3 ; walk_num_tot |] ~data:walkers_list);
|
||||
send_log "status" walk_num_tot t0 "Saved walkers";
|
||||
last_save_walkers := Time.now ();
|
||||
last_save_walkers := Unix.gettimeofday ();
|
||||
end
|
||||
in
|
||||
|
||||
@ -245,7 +249,7 @@ let run ?(daemon=true) ezfio_filename =
|
||||
disk if the array of walkers is filled. In that case, sets the last_walker to 0.
|
||||
*)
|
||||
let increment_last_walker () =
|
||||
last_walker := !last_walker + 1;
|
||||
incr last_walker;
|
||||
if (!last_walker = walk_num_tot) then
|
||||
begin
|
||||
last_walker := 0 ;
|
||||
@ -266,16 +270,16 @@ let run ?(daemon=true) ezfio_filename =
|
||||
|
||||
(** The hash table for workers *)
|
||||
let workers_hash =
|
||||
String.Table.create ()
|
||||
Hashtbl.create 63
|
||||
in
|
||||
|
||||
|
||||
|
||||
(** Creates a key using the couple ([Compute_node], [PID]) *)
|
||||
let key compute_node pid =
|
||||
String.concat [
|
||||
(Compute_node.to_string compute_node); " ";
|
||||
(Pid.to_string pid) ]
|
||||
String.concat " " [
|
||||
(Compute_node.to_string compute_node);
|
||||
(string_of_int pid) ]
|
||||
in
|
||||
|
||||
|
||||
@ -286,9 +290,9 @@ let run ?(daemon=true) ezfio_filename =
|
||||
let s =
|
||||
key w pid
|
||||
in
|
||||
match Hashtbl.add workers_hash ~key:s ~data:(Time.now ()) with
|
||||
| `Ok -> ()
|
||||
| `Duplicate -> failwith (s^" already registered")
|
||||
match Hashtbl.find_opt workers_hash s with
|
||||
| Some _ -> failwith (s^" already registered")
|
||||
| None -> Hashtbl.add workers_hash s (Unix.gettimeofday ())
|
||||
in
|
||||
|
||||
|
||||
@ -299,29 +303,33 @@ let run ?(daemon=true) ezfio_filename =
|
||||
let s =
|
||||
key w pid
|
||||
in
|
||||
match Hashtbl.find workers_hash s with
|
||||
match Hashtbl.find_opt workers_hash s with
|
||||
| Some x -> Hashtbl.remove workers_hash s
|
||||
| None -> failwith (s^" not registered")
|
||||
in
|
||||
|
||||
|
||||
|
||||
(** Sets the last access of the worker to [Time.now ()] *)
|
||||
(** Sets the last access of the worker to [Unix.gettimeofday ()] *)
|
||||
let touch_worker w pid =
|
||||
let s =
|
||||
key w pid
|
||||
in
|
||||
Hashtbl.set workers_hash ~key:s ~data:(Time.now ())
|
||||
Hashtbl.replace workers_hash s (Unix.gettimeofday ())
|
||||
in
|
||||
|
||||
|
||||
(** Returns the number of connected workers *)
|
||||
let n_connected hash now =
|
||||
let delta =
|
||||
Time.Span.of_sec (initialization_timeout +. block_time *. 2.)
|
||||
initialization_timeout +. block_time *. 2.
|
||||
in
|
||||
Hashtbl.filter hash ~f:(fun x -> (Time.abs_diff now x) <= delta)
|
||||
|> Hashtbl.length
|
||||
Hashtbl.fold (fun k v accu ->
|
||||
if (now -. v) <= delta then
|
||||
v :: accu
|
||||
else
|
||||
accu ) hash []
|
||||
|> List.length
|
||||
in
|
||||
|
||||
|
||||
@ -339,12 +347,11 @@ let run ?(daemon=true) ezfio_filename =
|
||||
Lazy.force Block.dir_name
|
||||
in
|
||||
let () =
|
||||
match Sys.is_directory dirname with
|
||||
| `Yes -> ()
|
||||
| _ -> Unix.mkdir_p dirname
|
||||
if not ( Sys.file_exists dirname ) then
|
||||
Unix.mkdir dirname 0o755
|
||||
in
|
||||
Filename.concat dirname (
|
||||
hostname ^ "." ^ (Pid.to_string dataserver_pid)
|
||||
hostname ^ "." ^ (string_of_int dataserver_pid)
|
||||
)
|
||||
in
|
||||
|
||||
@ -361,14 +368,14 @@ let run ?(daemon=true) ezfio_filename =
|
||||
(** [Out_channel] corresponding to the blocks file written by the current process. *)
|
||||
let block_channel =
|
||||
try
|
||||
ref (Out_channel.create block_channel_filename_locked)
|
||||
ref (open_out block_channel_filename_locked)
|
||||
with
|
||||
| Sys_error _ ->
|
||||
begin
|
||||
(* NFS Stale file handle :
|
||||
* Wait 5 seconds, and retry *)
|
||||
Time.Span.of_sec 5. |> Time.pause;
|
||||
ref (Out_channel.create block_channel_filename_locked)
|
||||
Unix.sleep 5;
|
||||
ref (open_out block_channel_filename_locked)
|
||||
end
|
||||
in
|
||||
|
||||
@ -379,13 +386,16 @@ let run ?(daemon=true) ezfio_filename =
|
||||
*)
|
||||
let compress_block_file filename =
|
||||
let t0 =
|
||||
Time.now ()
|
||||
Unix.gettimeofday ()
|
||||
in
|
||||
Out_channel.close !block_channel;
|
||||
Unix.rename ~src:block_channel_filename_locked ~dst:block_channel_filename_tmp;
|
||||
close_out !block_channel;
|
||||
Unix.rename block_channel_filename_locked block_channel_filename_tmp;
|
||||
Random_variable.compress_files ();
|
||||
send_log "status" 0 t0 "Compressed block file";
|
||||
block_channel := Out_channel.create ~append:true block_channel_filename_locked
|
||||
if Sys.file_exists block_channel_filename_locked then
|
||||
block_channel := open_out_gen [ Open_append ] 0o660 block_channel_filename_locked
|
||||
else
|
||||
block_channel := open_out block_channel_filename_locked
|
||||
in
|
||||
|
||||
|
||||
@ -396,7 +406,7 @@ let run ?(daemon=true) ezfio_filename =
|
||||
|
||||
let start_status_thread =
|
||||
let t0 =
|
||||
Time.now ()
|
||||
Unix.gettimeofday ()
|
||||
in
|
||||
Thread.create (fun () ->
|
||||
send_log "status" 0 t0 "Starting status thread";
|
||||
@ -407,16 +417,14 @@ let run ?(daemon=true) ezfio_filename =
|
||||
Printf.sprintf "tcp://*:%d" (port+1)
|
||||
in
|
||||
bind_socket "PUB" socket address;
|
||||
let delay =
|
||||
Time.Span.of_ms 300.
|
||||
and delay_read =
|
||||
Time.Span.of_sec 2.
|
||||
let delay = 0.3
|
||||
and delay_read = 2.
|
||||
in
|
||||
|
||||
let start_time =
|
||||
Time.now ()
|
||||
Unix.gettimeofday ()
|
||||
and stop_time =
|
||||
ref (Time.Span.of_sec Input.Stop_time.(read () |> to_float) )
|
||||
ref (Input.Stop_time.(read () |> to_float) )
|
||||
in
|
||||
|
||||
let last_update =
|
||||
@ -425,9 +433,9 @@ let run ?(daemon=true) ezfio_filename =
|
||||
|
||||
while (!status <> Status.Stopped)
|
||||
do
|
||||
Time.pause delay;
|
||||
Unix.sleepf delay;
|
||||
let now =
|
||||
Time.now ()
|
||||
Unix.gettimeofday ()
|
||||
in
|
||||
let status_string =
|
||||
Status.to_string !status
|
||||
@ -436,14 +444,14 @@ let run ?(daemon=true) ezfio_filename =
|
||||
send_log "status" (String.length status_string) now status_string;
|
||||
|
||||
let test =
|
||||
if (Time.abs_diff now !last_update > delay_read) then
|
||||
if (now -. !last_update > delay_read) then
|
||||
let n_connect =
|
||||
n_connected workers_hash now
|
||||
in
|
||||
`Update n_connect
|
||||
else if (Time.abs_diff now start_time > !stop_time) then
|
||||
else if (now -. start_time > !stop_time) then
|
||||
`Terminate
|
||||
else if (Time.abs_diff now start_time > Time.Span.of_sec initialization_timeout) then
|
||||
else if (now -. start_time > initialization_timeout) then
|
||||
`Timeout
|
||||
else
|
||||
`None
|
||||
@ -458,7 +466,7 @@ let run ?(daemon=true) ezfio_filename =
|
||||
begin
|
||||
status := Status.read ();
|
||||
last_update := now;
|
||||
stop_time := Time.Span.of_sec Input.Stop_time.(read () |> to_float) ;
|
||||
stop_time := Input.Stop_time.(read () |> to_float) ;
|
||||
let n_tot =
|
||||
Hashtbl.length workers_hash
|
||||
in
|
||||
@ -482,7 +490,7 @@ let run ?(daemon=true) ezfio_filename =
|
||||
|
||||
let start_log_thread =
|
||||
let t0 =
|
||||
Time.now ()
|
||||
Unix.gettimeofday ()
|
||||
in
|
||||
Thread.create (fun () ->
|
||||
send_log "status" 0 t0 "Starting log thread";
|
||||
@ -509,10 +517,10 @@ let run ?(daemon=true) ezfio_filename =
|
||||
begin
|
||||
let message =
|
||||
Zmq.Socket.recv_all ~block:false socket
|
||||
|> String.concat ~sep:" "
|
||||
|> String.concat " "
|
||||
in
|
||||
let now =
|
||||
Time.now ()
|
||||
Unix.gettimeofday ()
|
||||
in
|
||||
send_log "log" 0 now message
|
||||
end
|
||||
@ -548,7 +556,7 @@ let run ?(daemon=true) ezfio_filename =
|
||||
|
||||
let start_main_thread =
|
||||
let wall0 =
|
||||
Time.now ()
|
||||
Unix.gettimeofday ()
|
||||
in
|
||||
let f () =
|
||||
|
||||
@ -569,19 +577,18 @@ let run ?(daemon=true) ezfio_filename =
|
||||
|
||||
(** EZFIO Cache *)
|
||||
let ezfio_cache =
|
||||
String.Table.create ()
|
||||
Hashtbl.create 63
|
||||
in
|
||||
let handle_ezfio msg =
|
||||
match Hashtbl.find ezfio_cache msg with
|
||||
match Hashtbl.find_opt ezfio_cache msg with
|
||||
| Some result -> result
|
||||
| None ->
|
||||
begin
|
||||
let result =
|
||||
decode_ezfio_message msg
|
||||
in
|
||||
match (Hashtbl.add ezfio_cache ~key:msg ~data:result) with
|
||||
| `Ok -> result
|
||||
| `Duplicate -> result
|
||||
Hashtbl.add ezfio_cache msg result;
|
||||
result
|
||||
end
|
||||
in
|
||||
|
||||
@ -620,13 +627,13 @@ let run ?(daemon=true) ezfio_filename =
|
||||
Zmq.Socket.recv_all ~block:false rep_socket
|
||||
in
|
||||
let t0 =
|
||||
Time.now ()
|
||||
Unix.gettimeofday ()
|
||||
in
|
||||
let msg =
|
||||
List.map ~f:String.strip raw_msg
|
||||
List.map String.trim raw_msg
|
||||
|> Message.create
|
||||
and msg_size =
|
||||
List.fold ~init:0 ~f:(fun accu x -> accu + (String.length x)) raw_msg
|
||||
List.fold_left (fun accu x -> accu + (String.length x)) 0 raw_msg
|
||||
in
|
||||
let handle = function
|
||||
| Message.Error _ -> ()
|
||||
@ -654,9 +661,9 @@ let run ?(daemon=true) ezfio_filename =
|
||||
| Status.Queued
|
||||
| Status.Running ->
|
||||
begin
|
||||
String.concat [ "Register : " ;
|
||||
(Compute_node.to_string w) ; " " ;
|
||||
(Pid.to_string pid) ]
|
||||
String.concat " " [ "Register :" ;
|
||||
Compute_node.to_string w ;
|
||||
string_of_int pid ]
|
||||
|> send_log "req" msg_size t0;
|
||||
add_worker w pid;
|
||||
if (!status = Status.Queued) then
|
||||
@ -670,14 +677,14 @@ let run ?(daemon=true) ezfio_filename =
|
||||
end
|
||||
| Message.Unregister (w,pid) ->
|
||||
begin
|
||||
String.concat [ "Unregister : " ;
|
||||
(Compute_node.to_string w) ; " " ;
|
||||
(Pid.to_string pid) ]
|
||||
String.concat " " [ "Unregister :" ;
|
||||
(Compute_node.to_string w) ;
|
||||
(string_of_int pid) ]
|
||||
|> send_log "req" msg_size t0;
|
||||
Zmq.Socket.send rep_socket "OK";
|
||||
del_worker w pid;
|
||||
String.concat [ "Unregister : ";
|
||||
(Hashtbl.length workers_hash) |> Int.to_string ;
|
||||
String.concat " " [ "Unregister :";
|
||||
(Hashtbl.length workers_hash) |> string_of_int ;
|
||||
"remaining" ]
|
||||
|> send_log "rep" 2 t0 ;
|
||||
let n_connect =
|
||||
@ -705,13 +712,13 @@ let run ?(daemon=true) ezfio_filename =
|
||||
Zmq.Socket.recv_all ~block:false pull_socket
|
||||
in
|
||||
let t0 =
|
||||
Time.now ()
|
||||
Unix.gettimeofday ()
|
||||
in
|
||||
let msg =
|
||||
List.map ~f:String.strip raw_msg
|
||||
List.map String.trim raw_msg
|
||||
|> Message.create
|
||||
and msg_size =
|
||||
List.fold ~init:0 ~f:(fun accu x -> accu + (String.length x)) raw_msg
|
||||
List.fold_left (fun accu x -> accu + (String.length x)) 0 raw_msg
|
||||
in
|
||||
let recv_log =
|
||||
send_log "pull" msg_size t0
|
||||
@ -730,22 +737,25 @@ let run ?(daemon=true) ezfio_filename =
|
||||
recv_log log_msg ;
|
||||
for i=0 to ((Array.length w)-1)
|
||||
do
|
||||
(*
|
||||
Array.replace walkers_array (!last_walker) (fun _ -> Array.map
|
||||
~f:Float.to_string w.(i));
|
||||
string_of_float w.(i));
|
||||
*)
|
||||
walkers_array.(!last_walker) <- Array.map string_of_float w.(i);
|
||||
increment_last_walker ();
|
||||
done;
|
||||
let wall =
|
||||
Printf.sprintf "%f %f # %s %s %s %d"
|
||||
(Time.Span.to_sec (Time.abs_diff (Time.now ()) wall0))
|
||||
(Unix.gettimeofday () -. wall0)
|
||||
1. (Property.to_string Property.Wall)
|
||||
hostname (Pid.to_string dataserver_pid) 1
|
||||
hostname (string_of_int dataserver_pid) 1
|
||||
|> Block.of_string
|
||||
in
|
||||
match wall with
|
||||
| Some wall ->
|
||||
begin
|
||||
Out_channel.output_string !block_channel (Block.to_string wall);
|
||||
Out_channel.output_char !block_channel '\n';
|
||||
output_string !block_channel (Block.to_string wall);
|
||||
output_char !block_channel '\n';
|
||||
end
|
||||
| _ -> ()
|
||||
end
|
||||
@ -753,8 +763,8 @@ let run ?(daemon=true) ezfio_filename =
|
||||
begin
|
||||
if (status = Status.Running) then
|
||||
touch_worker b.Block.compute_node b.Block.pid ;
|
||||
Out_channel.output_string !block_channel (Block.to_string b);
|
||||
Out_channel.output_char !block_channel '\n';
|
||||
output_string !block_channel (Block.to_string b);
|
||||
output_char !block_channel '\n';
|
||||
recv_log (Block.to_string b)
|
||||
end
|
||||
| Message.Test
|
||||
@ -780,22 +790,20 @@ let run ?(daemon=true) ezfio_filename =
|
||||
| Some Zmq.Poll.In -> handle_rep ()
|
||||
| _ ->
|
||||
begin
|
||||
Out_channel.flush !block_channel ;
|
||||
flush !block_channel ;
|
||||
let file_size =
|
||||
(Unix.stat block_channel_filename_locked).Unix.st_size
|
||||
|> Float.of_int64
|
||||
|> Byte_units.create `Bytes
|
||||
in
|
||||
if (file_size > !max_file_size) then
|
||||
begin
|
||||
compress_block_file ();
|
||||
max_file_size := Byte_units.scale file_size 1.2;
|
||||
max_file_size := (file_size * 12) / 10;
|
||||
end
|
||||
end
|
||||
end
|
||||
done;
|
||||
|
||||
List.iter ~f:(fun socket ->
|
||||
List.iter (fun socket ->
|
||||
Zmq.Socket.set_linger_period socket 1000 ;
|
||||
Zmq.Socket.close socket)
|
||||
[ rep_socket ; pull_socket ]
|
||||
@ -819,8 +827,8 @@ let run ?(daemon=true) ezfio_filename =
|
||||
Zmq.Context.terminate zmq_context;
|
||||
begin
|
||||
try
|
||||
Out_channel.close !block_channel;
|
||||
Unix.remove block_channel_filename_locked
|
||||
close_out !block_channel;
|
||||
Unix.unlink block_channel_filename_locked
|
||||
with
|
||||
| _ -> ()
|
||||
end;
|
||||
@ -830,27 +838,28 @@ let run ?(daemon=true) ezfio_filename =
|
||||
(** {3 Main function} *)
|
||||
|
||||
let t0 =
|
||||
Time.now ()
|
||||
Unix.gettimeofday ()
|
||||
in
|
||||
|
||||
(* Handle signals *)
|
||||
let handler s =
|
||||
Printf.printf "Dataserver received the %s signal... killing\n%!" (Signal.to_string s);
|
||||
Printf.printf "Dataserver received signal %d... killing\n%!" s;
|
||||
Watchdog.kill ();
|
||||
in
|
||||
List.iter [
|
||||
Signal.int ;
|
||||
Signal.term ;
|
||||
Signal.quit ;
|
||||
List.iter (fun s -> ignore @@ Sys.signal s (Sys.Signal_handle handler))
|
||||
[
|
||||
Sys.sigint ;
|
||||
Sys.sigterm ;
|
||||
Sys.sigquit ;
|
||||
]
|
||||
~f:(fun x -> Signal.Expert.handle x handler)
|
||||
;
|
||||
|
||||
|
||||
(* Run threads *)
|
||||
begin
|
||||
|
||||
try
|
||||
(List.iter ~f:Thread.join
|
||||
(List.iter Thread.join
|
||||
[ start_status_thread () ;
|
||||
start_log_thread () ;
|
||||
start_main_thread () ;
|
||||
@ -860,7 +869,7 @@ let run ?(daemon=true) ezfio_filename =
|
||||
begin
|
||||
print_endline "Trapped error. Waiting 10 seconds...";
|
||||
change_status Status.Stopping;
|
||||
Time.Span.of_sec 10. |> Time.pause;
|
||||
Unix.sleep 10;
|
||||
finalize ~t0;
|
||||
raise err
|
||||
end
|
||||
|
@ -1,6 +1,3 @@
|
||||
open Core
|
||||
|
||||
|
||||
let run ~t ezfio_filename=
|
||||
|
||||
Qputils.set_ezfio_filename ezfio_filename;
|
||||
@ -20,9 +17,9 @@ let run ~t ezfio_filename=
|
||||
|
||||
let address =
|
||||
match (Ezfio.get_simulation_http_server ()
|
||||
|> String.rsplit2 ~on:':' )
|
||||
|> String_ext.rsplit2 ~on:':' )
|
||||
with
|
||||
| Some (a,p) -> a^":"^( (Int.of_string p)+4 |> Int.to_string )
|
||||
| Some (a,p) -> a^":"^( (int_of_string p)+4 |> string_of_int )
|
||||
| None -> failwith "Badly formed address"
|
||||
in
|
||||
Zmq.Socket.connect socket address;
|
||||
@ -34,7 +31,7 @@ let run ~t ezfio_filename=
|
||||
Str.regexp " *: *"
|
||||
in
|
||||
let tot_size =
|
||||
ref (Byte_units.create `Bytes 0.)
|
||||
ref 0.
|
||||
in
|
||||
while true
|
||||
do
|
||||
@ -44,12 +41,12 @@ let run ~t ezfio_filename=
|
||||
let (socket, bytes) =
|
||||
match Str.split re_split msg with
|
||||
| socket :: bytes :: _ ->
|
||||
(socket, Byte_units.create `Bytes (Float.of_string bytes))
|
||||
| _ -> (print_endline msg ; ("", Byte_units.create `Bytes 0.))
|
||||
(socket, float_of_string bytes)
|
||||
| _ -> (print_endline msg ; ("", 0.))
|
||||
in
|
||||
tot_size := Byte_units.create `Bytes ((Byte_units.bytes !tot_size) +. (Byte_units.bytes bytes));
|
||||
Printf.printf "%s\n%!" (Byte_units.to_string !tot_size);
|
||||
Time.pause (Time.Span.of_sec 1.)
|
||||
tot_size := !tot_size +. bytes;
|
||||
Printf.printf "%f\n%!" !tot_size;
|
||||
Unix.sleep 1
|
||||
done
|
||||
end
|
||||
else
|
||||
@ -65,20 +62,29 @@ let run ~t ezfio_filename=
|
||||
|
||||
|
||||
|
||||
let spec =
|
||||
let open Command.Spec in
|
||||
empty
|
||||
+> flag "t" no_arg
|
||||
~doc:"Measure the throughput"
|
||||
+> anon ("ezfio_file" %: string)
|
||||
let command () =
|
||||
let open Command_line in
|
||||
begin
|
||||
set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command");
|
||||
set_description_doc "Debug ZeroMQ communications";
|
||||
[ { short='t' ; long="traffic" ; opt=Optional ;
|
||||
doc="Print traffic in bytes" ;
|
||||
arg=Without_arg } ;
|
||||
|
||||
anonymous "EZFIO_DIR" Mandatory "EZFIO directory" ]
|
||||
|> set_specs
|
||||
end;
|
||||
|
||||
let t = Command_line.get_bool "traffic" in
|
||||
let ezfio_file =
|
||||
match Command_line.anon_args () with
|
||||
| ezfio_file :: [] -> ezfio_file
|
||||
| _ -> (Command_line.help () ; failwith "Inconsistent command line")
|
||||
in
|
||||
|
||||
run t ezfio_file
|
||||
|
||||
|
||||
let command =
|
||||
Command.basic_spec
|
||||
~summary: "Debug ZeroMQ communications"
|
||||
~readme:(fun () -> "Gets debug information from the Zmq debug sockets.")
|
||||
spec
|
||||
(fun t ezfio_file () -> run t ezfio_file)
|
||||
|
||||
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
open Core
|
||||
|
||||
let file_header filename = Printf.sprintf
|
||||
"
|
||||
+----------------------------------------------------------------+
|
||||
@ -12,7 +10,7 @@ Editing file `%s`
|
||||
|
||||
let make_header s =
|
||||
let l = String.length s in
|
||||
"\n\n"^s^"\n"^(String.init l ~f:(fun _ -> '='))^"\n\n"
|
||||
"\n\n"^s^"\n"^(String.init l (fun _ -> '='))^"\n\n"
|
||||
|
||||
|
||||
type field =
|
||||
@ -84,11 +82,11 @@ let create_temp_file ?temp_filename ezfio_filename fields =
|
||||
| None -> Filename.temp_file "qmcchem_edit_" ".rst"
|
||||
| Some name -> name
|
||||
in
|
||||
Out_channel.with_file filename ~f:(fun out_channel ->
|
||||
(file_header ezfio_filename) :: (List.map ~f:get fields)
|
||||
|> String.concat ~sep:"\n"
|
||||
|> Out_channel.output_string out_channel
|
||||
)
|
||||
let out_channel = open_out filename in
|
||||
(file_header ezfio_filename) :: (List.map get fields)
|
||||
|> String.concat "\n"
|
||||
|> output_string out_channel
|
||||
; close_out out_channel
|
||||
; filename
|
||||
|
||||
|
||||
@ -104,7 +102,7 @@ let write_input_in_ezfio ezfio_filename fields =
|
||||
let input_filename =
|
||||
create_temp_file ~temp_filename ezfio_filename fields
|
||||
in
|
||||
assert (Sys.file_exists_exn input_filename)
|
||||
assert (Sys.file_exists input_filename)
|
||||
|
||||
|
||||
(** Run the edit command *)
|
||||
@ -133,19 +131,19 @@ let run ~c ?f ?t ?l ?m ?e ?et ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_filename =
|
||||
in ();
|
||||
in
|
||||
|
||||
handle_option Input.Ref_energy.(of_float , write) e;
|
||||
handle_option Input.Trial_wf_energy.(of_float , write) et;
|
||||
handle_option Input.Ref_energy.(of_string, write) e;
|
||||
handle_option Input.Trial_wf_energy.(of_string, write) et;
|
||||
handle_option Input.Jastrow_type.(of_string, write) j;
|
||||
handle_option Input.Block_time.(of_int , write) l;
|
||||
handle_option Input.Block_time.(of_string, write) l;
|
||||
handle_option Input.Method.(of_string, write) m;
|
||||
handle_option Input.Stop_time.(of_int , write) t;
|
||||
handle_option Input.Stop_time.(of_string, write) t;
|
||||
handle_option Input.Sampling.(of_string, write) s;
|
||||
handle_option Input.Fitcusp_factor.(of_float , write) f;
|
||||
handle_option Input.Time_step.(of_float , write) ts;
|
||||
handle_option Input.Walk_num.(of_int , write) w;
|
||||
handle_option Input.Walk_num_tot.(of_int , write) wt;
|
||||
handle_option Input.CI_threshold.(of_float , write) n;
|
||||
handle_option Input.SRMC_projection_time.(of_float , write) p;
|
||||
handle_option Input.Fitcusp_factor.(of_string, write) f;
|
||||
handle_option Input.Time_step.(of_string, write) ts;
|
||||
handle_option Input.Walk_num.(of_string, write) w;
|
||||
handle_option Input.Walk_num_tot.(of_string, write) wt;
|
||||
handle_option Input.CI_threshold.(of_string, write) n;
|
||||
handle_option Input.SRMC_projection_time.(of_string, write) p;
|
||||
|
||||
|
||||
let fields =
|
||||
@ -179,21 +177,24 @@ let run ~c ?f ?t ?l ?m ?e ?et ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_filename =
|
||||
if (not !interactive) then
|
||||
failwith "Input file not allowed with command line arguments"
|
||||
else
|
||||
begin
|
||||
let rc =
|
||||
Printf.sprintf "cp %s %s" filename temp_filename
|
||||
|> Sys.command_exn ;
|
||||
end
|
||||
|> Sys.command
|
||||
in
|
||||
assert (rc = 0)
|
||||
end
|
||||
| None ->
|
||||
begin
|
||||
(* Open the temp file with external editor *)
|
||||
let editor =
|
||||
match Sys.getenv "EDITOR" with
|
||||
| Some editor -> editor
|
||||
| None -> "vi"
|
||||
try Sys.getenv "EDITOR" with
|
||||
| Not_found -> "vi"
|
||||
in
|
||||
let rc =
|
||||
Printf.sprintf "%s %s ; tput sgr0 2> /dev/null" editor temp_filename
|
||||
|> Sys.command_exn
|
||||
|> Sys.command
|
||||
in
|
||||
assert (rc = 0)
|
||||
end
|
||||
in
|
||||
|
||||
@ -203,18 +204,20 @@ let run ~c ?f ?t ?l ?m ?e ?et ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_filename =
|
||||
and re_prop =
|
||||
Str.regexp "([ xX]) .*$"
|
||||
and raw_data =
|
||||
In_channel.with_file temp_filename ~f:In_channel.input_lines
|
||||
let ic = open_in temp_filename in
|
||||
let result = String_ext.input_lines ic in
|
||||
close_in ic ; result
|
||||
in
|
||||
let data =
|
||||
( List.filter raw_data ~f:(fun x -> Str.string_match re_data x 0)
|
||||
|> List.map ~f:String.strip ) @
|
||||
( List.filter (fun x -> Str.string_match re_data x 0) raw_data
|
||||
|> List.map String.trim ) @
|
||||
[
|
||||
List.filter raw_data ~f:(fun x -> Str.string_match re_prop x 0)
|
||||
|> List.map ~f:String.strip
|
||||
|> String.concat ~sep:"\n" ]
|
||||
List.filter (fun x -> Str.string_match re_prop x 0) raw_data
|
||||
|> List.map String.trim
|
||||
|> String.concat "\n" ]
|
||||
in
|
||||
let open Input in
|
||||
List.iter2_exn data fields ~f:(fun s f ->
|
||||
List.iter2 (fun s f ->
|
||||
try
|
||||
begin
|
||||
match f with
|
||||
@ -235,7 +238,7 @@ let run ~c ?f ?t ?l ?m ?e ?et ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_filename =
|
||||
end
|
||||
with
|
||||
| Failure msg -> Printf.eprintf "%s\n" msg
|
||||
);
|
||||
) data fields ;
|
||||
|
||||
(* Remove temp_file *)
|
||||
Sys.remove temp_filename;
|
||||
@ -249,19 +252,18 @@ let run ~c ?f ?t ?l ?m ?e ?et ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_filename =
|
||||
Filename.concat (Filename.concat ezfio_filename "blocks") (QmcMd5.hash ())
|
||||
in
|
||||
let rec clean_dir y =
|
||||
match Sys.is_directory y with
|
||||
| `Yes ->
|
||||
Sys.ls_dir y
|
||||
|> List.map ~f:(Filename.concat y)
|
||||
|> List.iter ~f:(function x ->
|
||||
match ( Sys.is_directory x, Sys.is_file x ) with
|
||||
| (`Yes, _) -> clean_dir x
|
||||
| (_, `Yes) -> Sys.remove x
|
||||
| (_,_) -> ()
|
||||
if Sys.file_exists y && Sys.is_directory y then
|
||||
begin
|
||||
Sys.readdir y
|
||||
|> Array.map (fun x -> Filename.concat y x)
|
||||
|> Array.iter (function x ->
|
||||
if Sys.file_exists x && Sys.is_directory x then
|
||||
clean_dir x
|
||||
else
|
||||
Sys.remove x
|
||||
);
|
||||
Unix.rmdir y
|
||||
| `Unknown
|
||||
| `No -> ()
|
||||
end
|
||||
in clean_dir dirname;
|
||||
Printf.printf "Blocks cleared\n"
|
||||
end
|
||||
@ -272,51 +274,96 @@ let run ~c ?f ?t ?l ?m ?e ?et ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_filename =
|
||||
write_input_in_ezfio ezfio_filename fields
|
||||
|
||||
|
||||
let spec =
|
||||
let open Command.Spec in
|
||||
empty
|
||||
+> flag "c" no_arg
|
||||
~doc:(" Clear blocks")
|
||||
+> flag "f" (optional float)
|
||||
~doc:("float "^Input.Fitcusp_factor.doc)
|
||||
+> flag "t" (optional int)
|
||||
~doc:("seconds "^Input.Stop_time.doc)
|
||||
+> flag "l" (optional int)
|
||||
~doc:("seconds "^Input.Block_time.doc)
|
||||
+> flag "m" (optional string)
|
||||
~doc:("method "^Input.Method.doc)
|
||||
+> flag "e" (optional float)
|
||||
~doc:("energy "^Input.Ref_energy.doc)
|
||||
+> flag "et" (optional float)
|
||||
~doc:("energy "^Input.Trial_wf_energy.doc)
|
||||
+> flag "s" (optional string)
|
||||
~doc:("sampling "^Input.Sampling.doc)
|
||||
+> flag "ts" (optional float)
|
||||
~doc:("time_step "^Input.Time_step.doc)
|
||||
+> flag "w" (optional int)
|
||||
~doc:("walk_num "^Input.Walk_num.doc)
|
||||
+> flag "wt" (optional int)
|
||||
~doc:("walk_num_tot "^Input.Walk_num_tot.doc)
|
||||
+> flag "n" (optional float)
|
||||
~doc:("norm "^Input.CI_threshold.doc)
|
||||
+> flag "j" (optional string)
|
||||
~doc:("jastrow_type "^Input.Jastrow_type.doc)
|
||||
+> flag "p" (optional float)
|
||||
~doc:("projection_time "^Input.SRMC_projection_time.doc)
|
||||
+> anon ("ezfio_file" %: string)
|
||||
+> anon (maybe ("input" %: string))
|
||||
;;
|
||||
let command () =
|
||||
let open Command_line in
|
||||
begin
|
||||
set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command");
|
||||
set_description_doc "Edits input data";
|
||||
|
||||
let command =
|
||||
Command.basic_spec
|
||||
~summary: "Edit input data"
|
||||
~readme:(fun () ->
|
||||
"
|
||||
Edit input data
|
||||
")
|
||||
spec
|
||||
(fun c f t l m e et s ts w wt n j p ezfio_file input () ->
|
||||
run ~c ?f ?t ?l ?m ?e ?et ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_file )
|
||||
[ { short='c' ; long="clear" ; opt=Optional ;
|
||||
doc="Clears blocks" ;
|
||||
arg=Without_arg ; };
|
||||
|
||||
{ short='e' ; long="ref-energy" ; opt=Optional ;
|
||||
doc=Input.Ref_energy.doc;
|
||||
arg=With_arg "<float>"; };
|
||||
|
||||
{ short='f' ; long="fitcusp" ; opt=Optional ;
|
||||
doc=Input.Fitcusp_factor.doc;
|
||||
arg=With_arg "<float>"; };
|
||||
|
||||
{ short='i' ; long="time-step" ; opt=Optional ;
|
||||
doc=Input.Time_step.doc;
|
||||
arg=With_arg "<float>"; };
|
||||
|
||||
{ short='j' ; long="jastrow" ; opt=Optional ;
|
||||
doc=Input.Jastrow_type.doc;
|
||||
arg=With_arg "<string>"; };
|
||||
|
||||
{ short='l' ; long="block-time" ; opt=Optional ;
|
||||
doc=Input.Block_time.doc;
|
||||
arg=With_arg "<int>"; };
|
||||
|
||||
{ short='m' ; long="method" ; opt=Optional ;
|
||||
doc=Input.Method.doc;
|
||||
arg=With_arg "<string>"; };
|
||||
|
||||
{ short='n' ; long="norm" ; opt=Optional ;
|
||||
doc=Input.CI_threshold.doc;
|
||||
arg=With_arg "<float>"; };
|
||||
|
||||
{ short='p' ; long="projection-time" ; opt=Optional ;
|
||||
doc=Input.SRMC_projection_time.doc;
|
||||
arg=With_arg "<float>"; };
|
||||
|
||||
{ short='r' ; long="trial-energy" ; opt=Optional ;
|
||||
doc=Input.Trial_wf_energy.doc;
|
||||
arg=With_arg "<float>"; };
|
||||
|
||||
{ short='s' ; long="sampling" ; opt=Optional ;
|
||||
doc=Input.Sampling.doc;
|
||||
arg=With_arg "<string>"; };
|
||||
|
||||
{ short='t' ; long="stop-time" ; opt=Optional ;
|
||||
doc=Input.Stop_time.doc;
|
||||
arg=With_arg "<int>"; };
|
||||
|
||||
{ short='w' ; long="walk-num" ; opt=Optional ;
|
||||
doc=Input.Walk_num.doc;
|
||||
arg=With_arg "<int>"; };
|
||||
|
||||
{ short='x' ; long="walk-num-tot" ; opt=Optional ;
|
||||
doc=Input.Walk_num_tot.doc;
|
||||
arg=With_arg "<int>"; };
|
||||
|
||||
anonymous "EZFIO_DIR" Mandatory "EZFIO directory";
|
||||
anonymous "FILE" Optional "Name of the input file";
|
||||
]
|
||||
|> set_specs
|
||||
end;
|
||||
|
||||
let c = Command_line.get_bool "clear" in
|
||||
let f = Command_line.get "fitcusp" in
|
||||
let t = Command_line.get "stop-time" in
|
||||
let l = Command_line.get "block-time" in
|
||||
let m = Command_line.get "method" in
|
||||
let e = Command_line.get "ref-energy" in
|
||||
let et = Command_line.get "trial-energy" in
|
||||
let s = Command_line.get "stop-time" in
|
||||
let ts = Command_line.get "time-step" in
|
||||
let w = Command_line.get "walk-num" in
|
||||
let wt = Command_line.get "walk-num-tot" in
|
||||
let n = Command_line.get "norm" in
|
||||
let j = Command_line.get "jastrow" in
|
||||
let p = Command_line.get "projection-time" in
|
||||
|
||||
let ezfio_file, input =
|
||||
match Command_line.anon_args () with
|
||||
| ezfio_file :: [] -> ezfio_file, None
|
||||
| ezfio_file :: file :: [] -> ezfio_file, (Some file)
|
||||
| _ -> (Command_line.help () ; failwith "Inconsistent command line")
|
||||
in
|
||||
run ~c ?f ?t ?l ?m ?e ?et ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_file
|
||||
|
||||
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
open Core
|
||||
|
||||
let bind_socket ~socket_type ~socket ~address =
|
||||
let rec loop = function
|
||||
| 0 -> failwith @@ Printf.sprintf
|
||||
@ -11,7 +9,7 @@ let bind_socket ~socket_type ~socket ~address =
|
||||
Zmq.Socket.bind socket address;
|
||||
loop (-1)
|
||||
with
|
||||
| Unix.Unix_error _ -> (Time.pause @@ Time.Span.of_sec 1. ; loop (i-1) )
|
||||
| Unix.Unix_error _ -> (Unix.sleep 1 ; loop (i-1) )
|
||||
| other_exception -> raise other_exception
|
||||
in loop 10
|
||||
|
||||
@ -20,9 +18,8 @@ let bind_socket ~socket_type ~socket ~address =
|
||||
let run ezfio_filename dataserver =
|
||||
|
||||
let dataserver_address, dataserver_port =
|
||||
Substring.create ~pos:6 (Bytes.of_string dataserver)
|
||||
|> Substring.to_string
|
||||
|> String.lsplit2_exn ~on:':'
|
||||
String.sub dataserver 6 (String.length dataserver - 6)
|
||||
|> String_ext.lsplit2_exn ~on:':'
|
||||
and qmc =
|
||||
Lazy.force Qmcchem_config.qmc
|
||||
in
|
||||
@ -36,14 +33,14 @@ let run ezfio_filename dataserver =
|
||||
|
||||
(* Port of the data server *)
|
||||
let port =
|
||||
(Int.of_string dataserver_port)+10
|
||||
(int_of_string dataserver_port)+10
|
||||
in
|
||||
|
||||
(* Build qmc executable command *)
|
||||
let prog, argv =
|
||||
qmc,
|
||||
[ qmc ; ezfio_filename ;
|
||||
Printf.sprintf "ipc://%s:%d" Qmcchem_config.dev_shm port ];
|
||||
[| qmc ; ezfio_filename ;
|
||||
Printf.sprintf "ipc://%s:%d" Qmcchem_config.dev_shm port |];
|
||||
in
|
||||
|
||||
(* Create the temporary directory. If it is possible, then the process is a
|
||||
@ -51,47 +48,44 @@ let run ezfio_filename dataserver =
|
||||
*)
|
||||
let () =
|
||||
try
|
||||
Unix.mkdir tmpdir;
|
||||
Unix.mkdir tmpdir 0o755;
|
||||
Unix.chdir tmpdir
|
||||
with
|
||||
| Unix.Unix_error _ ->
|
||||
begin
|
||||
Unix.chdir tmpdir;
|
||||
Time.pause @@ Time.Span.of_sec 0.1;
|
||||
match (Sys.file_exists "PID") with
|
||||
| `No
|
||||
| `Unknown -> ()
|
||||
| `Yes ->
|
||||
Unix.sleepf 0.1 ;
|
||||
if Sys.file_exists "PID" then
|
||||
begin
|
||||
let pid =
|
||||
In_channel.with_file "PID" ~f:(fun ic ->
|
||||
match (In_channel.input_line ic) with
|
||||
| Some x -> x
|
||||
| None -> "-1" )
|
||||
|> Int.of_string
|
||||
let ic = open_in "PID" in
|
||||
try
|
||||
int_of_string (input_line ic)
|
||||
with
|
||||
| End_of_file -> -1
|
||||
in
|
||||
match pid with
|
||||
| -1 -> ()
|
||||
| pid ->
|
||||
begin
|
||||
match Signal.send (Signal.of_system_int 0) (`Pid (Pid.of_int pid)) with
|
||||
| `No_such_process -> ()
|
||||
| _ -> ignore @@ Unix.exec ~prog ~argv ()
|
||||
try
|
||||
Unix.kill pid 0 ;
|
||||
ignore @@ Unix.execvp prog argv
|
||||
with
|
||||
| Unix.Unix_error (Unix.ESRCH, _, _) -> ()
|
||||
end
|
||||
end
|
||||
in
|
||||
|
||||
(* Now, only one forwarder will execute the following code *)
|
||||
Out_channel.with_file "PID" ~f:(fun oc ->
|
||||
let oc = open_out "PID" in
|
||||
Unix.getpid ()
|
||||
|> Pid.to_int
|
||||
|> Printf.sprintf "%d\n"
|
||||
|> Out_channel.output_string oc);
|
||||
|> output_string oc
|
||||
;
|
||||
|
||||
(* Fork a qmc *)
|
||||
ignore @@
|
||||
Watchdog.fork_exec ~prog ~argv ();
|
||||
|
||||
(* If there are MICs, use them here (TODO) *)
|
||||
Watchdog.fork_exec ~prog ~args:argv ();
|
||||
|
||||
(* Fetch input *)
|
||||
let zmq_context =
|
||||
@ -104,9 +98,10 @@ let run ezfio_filename dataserver =
|
||||
let command =
|
||||
Printf.sprintf "rm -rf -- \"%s\" " tmpdir
|
||||
in
|
||||
match Unix.system command with
|
||||
| Ok _ -> ()
|
||||
| _ -> print_endline "Unable to remove temporary directory"
|
||||
try
|
||||
ignore @@ Unix.system command
|
||||
with
|
||||
| Unix.Unix_error _ -> print_endline "Unable to remove temporary directory"
|
||||
;
|
||||
Zmq.Context.terminate zmq_context ;
|
||||
for i=port to port+4
|
||||
@ -126,15 +121,15 @@ let run ezfio_filename dataserver =
|
||||
|
||||
(* Signal handler to Kill properly all the processes *)
|
||||
let handler s =
|
||||
Printf.printf "Forwarder received the %s signal... killing\n%!" (Signal.to_string s);
|
||||
Printf.printf "Forwarder received signal %d... killing\n%!" s;
|
||||
terminate ();
|
||||
in
|
||||
List.iter [
|
||||
Signal.int ;
|
||||
Signal.term ;
|
||||
Signal.quit ;
|
||||
List.iter (fun s -> ignore @@ Sys.signal s (Sys.Signal_handle handler))
|
||||
[
|
||||
Sys.sigint ;
|
||||
Sys.sigterm ;
|
||||
Sys.sigquit ;
|
||||
]
|
||||
~f:(fun x -> Signal.Expert.handle x handler)
|
||||
;
|
||||
|
||||
|
||||
@ -189,7 +184,7 @@ let run ezfio_filename dataserver =
|
||||
status := Status.of_string msg;
|
||||
end;
|
||||
done;
|
||||
List.iter ~f:(fun socket ->
|
||||
List.iter (fun socket ->
|
||||
Zmq.Socket.set_linger_period socket 1000 ;
|
||||
Zmq.Socket.close socket)
|
||||
[ sub_socket ; pub_socket ]
|
||||
@ -239,7 +234,7 @@ let run ezfio_filename dataserver =
|
||||
|> Zmq.Socket.send sub_socket ;
|
||||
end
|
||||
done;
|
||||
List.iter ~f:(fun socket ->
|
||||
List.iter (fun socket ->
|
||||
Zmq.Socket.set_linger_period socket 1000 ;
|
||||
Zmq.Socket.close socket)
|
||||
[ sub_socket ; pub_socket ]
|
||||
@ -268,7 +263,7 @@ let run ezfio_filename dataserver =
|
||||
Zmq.Socket.set_linger_period dealer_socket 600_000;
|
||||
|
||||
let fetch_walkers () =
|
||||
Zmq.Socket.send_all req_socket ["get_walkers" ; Int.to_string !walk_num ];
|
||||
Zmq.Socket.send_all req_socket ["get_walkers" ; string_of_int !walk_num ];
|
||||
Zmq.Socket.recv_all req_socket
|
||||
in
|
||||
|
||||
@ -280,10 +275,10 @@ let run ezfio_filename dataserver =
|
||||
|
||||
(* EZFIO Cache *)
|
||||
let ezfio_cache =
|
||||
String.Table.create ()
|
||||
Hashtbl.create 63
|
||||
in
|
||||
let handle_ezfio msg =
|
||||
match Hashtbl.find ezfio_cache msg with
|
||||
match Hashtbl.find_opt ezfio_cache msg with
|
||||
| Some result -> result
|
||||
| None ->
|
||||
begin
|
||||
@ -291,9 +286,8 @@ let run ezfio_filename dataserver =
|
||||
let result =
|
||||
Zmq.Socket.recv_all req_socket
|
||||
in
|
||||
match (Hashtbl.add ezfio_cache ~key:msg ~data:result) with
|
||||
| `Ok -> result
|
||||
| `Duplicate -> result
|
||||
Hashtbl.add ezfio_cache msg result;
|
||||
result
|
||||
end
|
||||
in
|
||||
|
||||
@ -315,7 +309,7 @@ let run ezfio_filename dataserver =
|
||||
| head :: tail -> aux (head::header) tail
|
||||
| _ -> failwith "Too many routers in the middle"
|
||||
in
|
||||
aux [] (List.map ~f:String.strip raw_msg)
|
||||
aux [] (List.map String.trim raw_msg)
|
||||
in
|
||||
let handle message =
|
||||
match message with
|
||||
@ -407,7 +401,7 @@ let run ezfio_filename dataserver =
|
||||
| head :: tail -> aux (head::header) tail
|
||||
| _ -> failwith "Too many routers in the middle"
|
||||
in
|
||||
aux [] (List.map ~f:String.strip raw_msg)
|
||||
aux [] (List.map String.trim raw_msg)
|
||||
in
|
||||
let handle message =
|
||||
match message with
|
||||
@ -469,16 +463,17 @@ let run ezfio_filename dataserver =
|
||||
match message with
|
||||
| "elec_coord":: hostname :: pid :: id :: n_str :: rest ->
|
||||
let n =
|
||||
Int.of_string n_str
|
||||
int_of_string n_str
|
||||
in
|
||||
let len =
|
||||
if !walk_num = 0 then n else
|
||||
n / !walk_num
|
||||
in
|
||||
if (n < 5*len) then
|
||||
message
|
||||
else
|
||||
List.concat [ [ "elec_coord" ; hostname ; pid ; id ;
|
||||
Int.to_string (5*len)] ; ( select_n_of ~n:5 ~len rest ) ]
|
||||
string_of_int (5*len)] ; ( select_n_of ~n:5 ~len rest ) ]
|
||||
| _ -> message
|
||||
in
|
||||
Zmq.Socket.send_all push_socket new_message
|
||||
@ -508,7 +503,7 @@ let run ezfio_filename dataserver =
|
||||
if (polling.(3) = Some Zmq.Poll.In) then
|
||||
handle_proxy ();
|
||||
done;
|
||||
List.iter ~f:(fun socket ->
|
||||
List.iter (fun socket ->
|
||||
Zmq.Socket.set_linger_period socket 1000 ;
|
||||
Zmq.Socket.close socket)
|
||||
[ router_socket ; dealer_socket ; push_socket ; pull_socket ; proxy_socket ]
|
||||
@ -520,7 +515,7 @@ let run ezfio_filename dataserver =
|
||||
(* Start the status thread and the main thread *)
|
||||
begin
|
||||
try
|
||||
(List.iter ~f:Thread.join
|
||||
(List.iter Thread.join
|
||||
[ start_status_thread ();
|
||||
start_log_thread ();
|
||||
start_proxy_thread ();
|
||||
@ -531,7 +526,7 @@ let run ezfio_filename dataserver =
|
||||
begin
|
||||
print_endline "Trapped error. Waiting 10 seconds...";
|
||||
status := Status.Stopping;
|
||||
Time.Span.of_sec 10. |> Time.pause;
|
||||
Unix.sleep 10 ;
|
||||
raise err
|
||||
end
|
||||
end;
|
||||
|
@ -1,4 +1,3 @@
|
||||
open Core
|
||||
|
||||
|
||||
let run ezfio_filename =
|
||||
@ -8,25 +7,25 @@ let run ezfio_filename =
|
||||
in
|
||||
let prog, argv =
|
||||
qmcchem_info,
|
||||
[ qmcchem_info ; ezfio_filename ]
|
||||
[| qmcchem_info ; ezfio_filename |]
|
||||
in
|
||||
ignore @@
|
||||
Unix.exec ~prog ~argv ()
|
||||
Unix.execvp prog argv
|
||||
|
||||
let command () =
|
||||
let open Command_line in
|
||||
begin
|
||||
set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command");
|
||||
set_description_doc "Display info on an EZFIO database";
|
||||
[ anonymous "EZFIO_DIR" Mandatory "EZFIO directory" ]
|
||||
|> set_specs
|
||||
end;
|
||||
|
||||
let spec =
|
||||
let open Command.Spec in
|
||||
empty
|
||||
+> anon ("ezfio_file" %: string)
|
||||
|
||||
let command =
|
||||
Command.basic_spec
|
||||
~summary: "Display info on an EZFIO database"
|
||||
~readme:(fun () ->
|
||||
"
|
||||
Display info on an EZFIO database
|
||||
")
|
||||
spec
|
||||
(fun ezfio_file () -> run ezfio_file )
|
||||
let ezfio_file =
|
||||
match Command_line.anon_args () with
|
||||
| ezfio_file :: [] -> ezfio_file
|
||||
| _ -> (Command_line.help () ; failwith "Inconsistent command line")
|
||||
in
|
||||
|
||||
run ezfio_file
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
open Core
|
||||
|
||||
let run ?c ?d ~l ~update ezfio_filename =
|
||||
|
||||
@ -22,7 +21,7 @@ let run ?c ?d ~l ~update ezfio_filename =
|
||||
let filename =
|
||||
filename_of_key key
|
||||
in
|
||||
Sys.file_exists_exn filename
|
||||
Sys.file_exists filename
|
||||
in
|
||||
|
||||
if (update) then
|
||||
@ -37,27 +36,28 @@ let run ?c ?d ~l ~update ezfio_filename =
|
||||
|
||||
if (old_key <> new_key) then
|
||||
begin
|
||||
let prefix =
|
||||
Filename.concat ezfio_filename "blocks"
|
||||
in
|
||||
let new_name =
|
||||
String.concat ~sep:"/" [ ezfio_filename; "blocks"; new_key ]
|
||||
Filename.concat prefix new_key
|
||||
and old_name =
|
||||
String.concat ~sep:"/" [ ezfio_filename; "blocks"; old_key ]
|
||||
Filename.concat prefix old_key
|
||||
in
|
||||
Printf.printf "Renaming %s -> %s\n" old_name new_name;
|
||||
try Sys.rename old_name new_name with
|
||||
| Sys_error _ -> ();
|
||||
|
||||
let old_name =
|
||||
String.concat ~sep:"/" [ ezfio_filename; "input"; old_key ]
|
||||
String.concat "/" [ ezfio_filename; "input"; old_key ]
|
||||
in
|
||||
Printf.printf "Removing %s\n%!" old_name;
|
||||
try Sys.remove old_name with
|
||||
| Sys_error _ -> ();
|
||||
end
|
||||
in
|
||||
let l =
|
||||
Sys.ls_dir input_directory
|
||||
in
|
||||
List.iter l ~f:(fun x -> update_one x) ;
|
||||
Sys.readdir input_directory
|
||||
|> Array.iter (fun x -> update_one x) ;
|
||||
Printf.printf "Done\n%!" ;
|
||||
end
|
||||
;
|
||||
@ -76,8 +76,8 @@ let run ?c ?d ~l ~update ezfio_filename =
|
||||
match l with
|
||||
| false -> ()
|
||||
| true ->
|
||||
Sys.ls_dir input_directory
|
||||
|> List.iter ~f:(fun md5 ->
|
||||
Sys.readdir input_directory
|
||||
|> Array.iter (fun md5 ->
|
||||
let filename =
|
||||
Filename.concat input_directory md5
|
||||
in
|
||||
@ -88,10 +88,9 @@ let run ?c ?d ~l ~update ezfio_filename =
|
||||
""
|
||||
in
|
||||
let date =
|
||||
(Unix.stat filename).Unix.st_mtime
|
||||
in
|
||||
let date =
|
||||
Unix.strftime (Unix.localtime date) "%a, %d %b %Y %T %z"
|
||||
let open Unix in
|
||||
localtime (stat filename).st_mtime
|
||||
|> Time.string_of_date
|
||||
in
|
||||
Printf.printf "%s : %s %s\n" md5 date this)
|
||||
in
|
||||
@ -102,13 +101,12 @@ let run ?c ?d ~l ~update ezfio_filename =
|
||||
| Some other_key ->
|
||||
if (key_is_valid other_key) then
|
||||
let command =
|
||||
String.concat ~sep:" "
|
||||
String.concat " "
|
||||
[ "diff" ; "-u" ; "-w" ;
|
||||
(filename_of_key current_md5) ;
|
||||
(filename_of_key other_key) ]
|
||||
in
|
||||
match (Unix.system command) with
|
||||
| _ -> ()
|
||||
ignore @@ Unix.system command
|
||||
else
|
||||
failwith ("Error: " ^ other_key ^ " does not exist")
|
||||
in
|
||||
@ -122,30 +120,45 @@ let run ?c ?d ~l ~update ezfio_filename =
|
||||
| _ -> handle_options ()
|
||||
|
||||
|
||||
let spec =
|
||||
let open Command.Spec in
|
||||
empty
|
||||
+> flag "c" (optional string)
|
||||
~doc:("<key> Change to input to <key>")
|
||||
+> flag "d" (optional string)
|
||||
~doc:("<key> Show input differences with <key>")
|
||||
+> flag "l" no_arg
|
||||
~doc:(" List all the saved MD5 keys.")
|
||||
+> flag "update" no_arg
|
||||
~doc:(" Update to the latest MD5 format.")
|
||||
+> anon ("ezfio_file" %: string)
|
||||
let command () =
|
||||
let open Command_line in
|
||||
begin
|
||||
set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command");
|
||||
set_description_doc "Manipulate input MD5 keys";
|
||||
|
||||
[ { short='c' ; long="clear" ; opt=Optional ;
|
||||
doc="Change to input to <key>" ;
|
||||
arg=With_arg "<string>" ; };
|
||||
|
||||
{ short='d' ; long="diff" ; opt=Optional ;
|
||||
doc="Show input differences with <key>" ;
|
||||
arg=With_arg "<string>" ; };
|
||||
|
||||
let command =
|
||||
Command.basic_spec
|
||||
~summary: "Manipulate input MD5 keys"
|
||||
~readme:(fun () ->
|
||||
"
|
||||
Manipulate input MD5 keys
|
||||
")
|
||||
spec
|
||||
(fun c d l update ezfio_file () -> run ?c ?d ~l ~update ezfio_file )
|
||||
{ short='l' ; long="list" ; opt=Optional ;
|
||||
doc="List all the saved MD5 keys." ;
|
||||
arg=Without_arg ; };
|
||||
|
||||
{ short='u' ; long="update" ; opt=Optional ;
|
||||
doc="Update to the latest MD5 format." ;
|
||||
arg=Without_arg ; };
|
||||
|
||||
anonymous "EZFIO_DIR" Mandatory "EZFIO directory";
|
||||
]
|
||||
|> set_specs
|
||||
end;
|
||||
|
||||
let update = Command_line.get_bool "update" in
|
||||
let c = Command_line.get "clear" in
|
||||
let d = Command_line.get "diff" in
|
||||
let l = Command_line.get_bool "list" in
|
||||
|
||||
let ezfio_file =
|
||||
match Command_line.anon_args () with
|
||||
| ezfio_file :: [] -> ezfio_file
|
||||
| _ -> (Command_line.help () ; failwith "Inconsistent command line")
|
||||
in
|
||||
|
||||
run ?c ?d ~l ~update ezfio_file
|
||||
|
||||
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
open Core
|
||||
open Qptypes
|
||||
|
||||
(** Display a table that can be plotted by gnuplot *)
|
||||
@ -12,19 +11,17 @@ let display_table ~range property =
|
||||
and data = p.Random_variable.data
|
||||
in
|
||||
let results =
|
||||
List.map2_exn conv rconv ~f:(fun (val1, err1) (val2,err2) -> (val1, err1, val2, err2))
|
||||
List.map2 (fun (val1, err1) (val2,err2) -> (val1, err1, val2, err2)) conv rconv
|
||||
in
|
||||
List.iter2_exn results data ~f:(fun (val1, err1, val2, err2) block ->
|
||||
List.iter2 (fun (val1, err1, val2, err2) block ->
|
||||
Printf.printf "%10.6f %10.6f %10.6f %10.6f %10.6f\n"
|
||||
val1 err1 val2 err2 (Sample.to_float block.Block.value)
|
||||
)
|
||||
;;
|
||||
) results data
|
||||
|
||||
|
||||
(** Display a convergence plot of the requested property *)
|
||||
let display_plot ~range property =
|
||||
print_string ("display_plot "^property^".\n")
|
||||
;;
|
||||
|
||||
|
||||
(** Display a convergence table of the error *)
|
||||
@ -51,7 +48,7 @@ let display_err_convergence ~range property =
|
||||
| (ave, None) -> ()
|
||||
in
|
||||
aux 1 p
|
||||
;;
|
||||
|
||||
|
||||
(** Display the centered cumulants of a property *)
|
||||
let display_cumulants ~range property =
|
||||
@ -71,7 +68,7 @@ let display_cumulants ~range property =
|
||||
1. /. 48. *. cum.(3) *. cum.(3)
|
||||
in
|
||||
Printf.printf "Non-gaussianity = %16.10f\n" n
|
||||
;;
|
||||
|
||||
|
||||
|
||||
(** Display a table for the autocovariance of the property *)
|
||||
@ -81,9 +78,9 @@ let display_autocovariance ~range property =
|
||||
|> Random_variable.of_raw_data ~range
|
||||
in
|
||||
Random_variable.autocovariance p
|
||||
|> List.iteri ~f:(fun i x ->
|
||||
|> List.iteri (fun i x ->
|
||||
Printf.printf "%10d %16.10f\n" i x)
|
||||
;;
|
||||
|
||||
|
||||
(** Display a histogram of the property *)
|
||||
let display_histogram ~range property =
|
||||
@ -104,8 +101,8 @@ let display_histogram ~range property =
|
||||
let g =
|
||||
Random_variable.GaussianDist.eval ~g
|
||||
in
|
||||
List.iter histo ~f:( fun (x,y) ->
|
||||
Printf.printf "%16.10f %16.10f %16.10f\n" x y (g ~x))
|
||||
List.iter ( fun (x,y) ->
|
||||
Printf.printf "%16.10f %16.10f %16.10f\n" x y (g ~x)) histo
|
||||
(*
|
||||
and sigma2 =
|
||||
(Random_variable.centered_cumulants p).(1)
|
||||
@ -128,7 +125,7 @@ let display_histogram ~range property =
|
||||
|> List.iter ~f:(fun (x,y,g) ->
|
||||
Printf.printf "%16.10f %16.10f %16.10f\n" x y g)
|
||||
*)
|
||||
;;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -144,7 +141,7 @@ let display_summary ~range =
|
||||
(Property.to_string property)
|
||||
(Random_variable.to_string p)
|
||||
in
|
||||
List.iter properties ~f:print_property ;
|
||||
List.iter print_property properties ;
|
||||
|
||||
|
||||
let cpu =
|
||||
@ -159,8 +156,8 @@ let display_summary ~range =
|
||||
let speedup =
|
||||
cpu /. wall
|
||||
in
|
||||
Printf.printf "%20s : %10.2f x\n" "Speedup" speedup;
|
||||
;;
|
||||
Printf.printf "%20s : %10.2f x\n" "Speedup" speedup
|
||||
|
||||
|
||||
|
||||
let run ?a ?c ?e ?h ?t ?p ?rmin ?rmax ezfio_file =
|
||||
@ -170,15 +167,15 @@ let run ?a ?c ?e ?h ?t ?p ?rmin ?rmax ezfio_file =
|
||||
let rmin =
|
||||
match rmin with
|
||||
| None -> 0.
|
||||
| Some x when (x<0) -> failwith "rmin should be >= 0"
|
||||
| Some x when (x>100) -> failwith "rmin should be <= 100"
|
||||
| Some x -> Float.of_int x
|
||||
| Some x when (float_of_string x < 0.) -> failwith "rmin should be >= 0"
|
||||
| Some x when (float_of_string x > 100.) -> failwith "rmin should be <= 100"
|
||||
| Some x -> float_of_string x
|
||||
and rmax =
|
||||
match rmax with
|
||||
| None -> 100.
|
||||
| Some x when (x<0) -> failwith "rmax should be >= 0"
|
||||
| Some x when (x>100) -> failwith "rmax should be <= 100"
|
||||
| Some x -> Float.of_int x
|
||||
| Some x when (float_of_string x < 0.) -> failwith "rmax should be >= 0"
|
||||
| Some x when (float_of_string x > 100.) -> failwith "rmax should be <= 100"
|
||||
| Some x -> float_of_string x
|
||||
in
|
||||
let range =
|
||||
(rmin, rmax)
|
||||
@ -194,54 +191,80 @@ let run ?a ?c ?e ?h ?t ?p ?rmin ?rmax ezfio_file =
|
||||
]
|
||||
in
|
||||
|
||||
let f (x,func) =
|
||||
List.iter (fun (x,func) ->
|
||||
match x with
|
||||
| Some property -> func ~range property
|
||||
| None -> ()
|
||||
in
|
||||
) l;
|
||||
|
||||
List.iter ~f l
|
||||
;
|
||||
|
||||
if (List.fold ~init:true ~f:(fun accu x ->
|
||||
if (List.fold_left (fun accu x ->
|
||||
match x with
|
||||
| (None, _) -> accu && true
|
||||
| (Some _,_) -> false
|
||||
) l
|
||||
) true l
|
||||
) then
|
||||
display_summary ~range
|
||||
;;
|
||||
|
||||
|
||||
let spec =
|
||||
let open Command.Spec in
|
||||
empty
|
||||
+> flag "a" (optional string)
|
||||
~doc:"property Display the autcovariance function of the property"
|
||||
+> flag "c" (optional string)
|
||||
~doc:"property Print the centered cumulants of a property"
|
||||
+> flag "e" (optional string)
|
||||
~doc:"property Display the convergence of the error of the property by merging blocks"
|
||||
+> flag "h" (optional string)
|
||||
~doc:"property Display the histogram of the property blocks"
|
||||
+> flag "p" (optional string)
|
||||
~doc:"property Display a convergence plot for a property"
|
||||
+> flag "rmin" (optional int)
|
||||
~doc:"int Lower bound of the percentage of the total weight to consider (default 0)"
|
||||
+> flag "rmax" (optional int)
|
||||
~doc:"int Upper bound of the percentage of the total weight to consider (default 100)"
|
||||
+> flag "t" (optional string)
|
||||
~doc:"property Print a table for the convergence of a property"
|
||||
+> anon ("ezfio_file" %: string)
|
||||
;;
|
||||
let command () =
|
||||
let open Command_line in
|
||||
begin
|
||||
set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command");
|
||||
set_description_doc "Displays the results computed in an EZFIO directory.";
|
||||
|
||||
let command =
|
||||
Command.basic_spec
|
||||
~summary: "Displays the results computed in an EZFIO directory."
|
||||
~readme:(fun () -> "Displays the results computed in an EZFIO directory.")
|
||||
spec
|
||||
(fun a c e h p rmin rmax t ezfio_file () -> run ?a ?c ?e ?h ?t ?p ?rmin ?rmax ezfio_file )
|
||||
;;
|
||||
[ { short='a' ; long="autocovariance" ; opt=Optional ;
|
||||
doc="Display the autcovariance function of the property";
|
||||
arg=With_arg "<string>" ; };
|
||||
|
||||
{ short='c' ; long="centered-cumulants" ; opt=Optional ;
|
||||
doc="Print the centered cumulants of a property" ;
|
||||
arg=With_arg "<string>"; };
|
||||
|
||||
{ short='e' ; long="error" ; opt=Optional ;
|
||||
doc="Display the convergence of the error of the property by merging blocks";
|
||||
arg=With_arg "<string>"; };
|
||||
|
||||
{ short='i' ; long="histogram" ; opt=Optional ;
|
||||
doc="Display the histogram of the property blocks" ;
|
||||
arg=With_arg "<string>"; };
|
||||
|
||||
{ short='p' ; long="plot" ; opt=Optional ;
|
||||
doc="Display a convergence plot for a property";
|
||||
arg=With_arg "<string>"; };
|
||||
|
||||
{ short='m' ; long="rmin" ; opt=Optional ;
|
||||
doc="Lower bound of the percentage of the total weight to consider (default 0)" ;
|
||||
arg=With_arg "<int>"; };
|
||||
|
||||
{ short='n' ; long="rmax" ; opt=Optional ;
|
||||
doc="Upper bound of the percentage of the total weight to consider (default 100)" ;
|
||||
arg=With_arg "<int>"; };
|
||||
|
||||
{ short='t' ; long="table" ; opt=Optional ;
|
||||
doc="Print a table for the convergence of a property" ;
|
||||
arg=With_arg "<string>"; };
|
||||
|
||||
anonymous "EZFIO_DIR" Mandatory "EZFIO directory";
|
||||
]
|
||||
|
||||
|> set_specs ;
|
||||
end;
|
||||
|
||||
let a = Command_line.get "autocovariance" in
|
||||
let c = Command_line.get "centered-cumulants" in
|
||||
let e = Command_line.get "error" in
|
||||
let h = Command_line.get "histogram" in
|
||||
let t = Command_line.get "table" in
|
||||
let p = Command_line.get "plot" in
|
||||
let rmin = Command_line.get "m" in
|
||||
let rmax = Command_line.get "n" in
|
||||
|
||||
let ezfio_file =
|
||||
match Command_line.anon_args () with
|
||||
| ezfio_file :: [] -> ezfio_file
|
||||
| _ -> (Command_line.help () ; failwith "Inconsistent command line")
|
||||
in
|
||||
run ?a ?c ?e ?h ?t ?p ?rmin ?rmax ezfio_file
|
||||
|
||||
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
open Core
|
||||
|
||||
let full_run ?(start_dataserver=true) ezfio_filename =
|
||||
(* Identify the job scheduler *)
|
||||
@ -39,17 +38,16 @@ let full_run ?(start_dataserver=true) ezfio_filename =
|
||||
|
||||
|
||||
(* Start the data server *)
|
||||
let prog, argv =
|
||||
qmcchem, [ qmcchem; "run" ; "-d" ; ezfio_filename]
|
||||
let prog, args =
|
||||
qmcchem, [| qmcchem; "run" ; "-d" ; ezfio_filename |]
|
||||
in
|
||||
let pid_dataserver =
|
||||
Watchdog.fork_exec ~prog ~argv ()
|
||||
Watchdog.fork_exec ~prog ~args ()
|
||||
in
|
||||
Printf.printf "%7d : %s\n%!" (Pid.to_int pid_dataserver) (String.concat ~sep:" " argv)
|
||||
Printf.printf "%7d : %s\n%!" pid_dataserver (String.concat " " (Array.to_list args))
|
||||
end;
|
||||
|
||||
|
||||
(*
|
||||
(* Check if the Zmq Rep socket is open *)
|
||||
let test_open_rep_socket () =
|
||||
let zmq_context =
|
||||
@ -87,7 +85,7 @@ let full_run ?(start_dataserver=true) ezfio_filename =
|
||||
| n ->
|
||||
if (not (test_open_rep_socket ())) then
|
||||
begin
|
||||
Time.pause (Time.Span.of_sec 0.5);
|
||||
Unix.sleep 2;
|
||||
count (n-1);
|
||||
end
|
||||
else
|
||||
@ -95,33 +93,33 @@ let full_run ?(start_dataserver=true) ezfio_filename =
|
||||
in
|
||||
if (not (count 300)) then
|
||||
Watchdog.kill ();
|
||||
*)
|
||||
Time.pause (Time.Span.of_sec 3.);
|
||||
Unix.sleep 3;
|
||||
|
||||
|
||||
(* Start the qmc processes *)
|
||||
let prog, argv =
|
||||
let prog, args_list =
|
||||
let launcher =
|
||||
Launcher.(find () |> to_string)
|
||||
in
|
||||
match launcher
|
||||
|> String.split ~on:' '
|
||||
|> List.map ~f:String.strip
|
||||
|> List.filter ~f:(fun x -> x <> "")
|
||||
|> String.split_on_char ' '
|
||||
|> List.map String.trim
|
||||
|> List.filter (fun x -> x <> "")
|
||||
with
|
||||
| launcher_exe::launcher_flags ->
|
||||
launcher_exe, launcher_exe :: launcher_flags @ qmc @ [
|
||||
Ezfio.get_simulation_http_server () ; ezfio_filename ]
|
||||
| _ -> failwith "Error in launcher"
|
||||
in
|
||||
let args = Array.of_list args_list in
|
||||
let pid_qmc =
|
||||
try
|
||||
Watchdog.fork_exec ~prog ~argv ()
|
||||
Watchdog.fork_exec ~prog ~args ()
|
||||
with
|
||||
| Unix.Unix_error _ ->
|
||||
begin
|
||||
let command =
|
||||
String.concat ~sep:" " argv
|
||||
String.concat " " args_list
|
||||
in
|
||||
Printf.printf "
|
||||
============================================================
|
||||
@ -132,7 +130,7 @@ Error: Unable to run the following command
|
||||
Watchdog.kill ()
|
||||
end
|
||||
in
|
||||
Printf.printf "%7d : %s\n%!" (Pid.to_int pid_qmc) (String.concat ~sep:" " argv);
|
||||
Printf.printf "%7d : %s\n%!" pid_qmc (String.concat " " args_list);
|
||||
|
||||
(* Wait for processes to finish *)
|
||||
Watchdog.join ()
|
||||
@ -153,17 +151,18 @@ let run a d ?q ?s ezfio_filename =
|
||||
|
||||
(* Signal handler to Kill properly all the processes *)
|
||||
let handler s =
|
||||
Printf.printf "QMC=Chem received the %s signal... killing\n%!" (Signal.to_string s);
|
||||
Printf.printf "QMC=Chem received signal %d... killing\n%!" s;
|
||||
Watchdog.kill ();
|
||||
in
|
||||
List.iter [
|
||||
Signal.int ;
|
||||
Signal.term ;
|
||||
Signal.quit ;
|
||||
List.iter (fun s -> ignore @@ Sys.signal s (Sys.Signal_handle handler))
|
||||
[
|
||||
Sys.sigint ;
|
||||
Sys.sigterm ;
|
||||
Sys.sigquit ;
|
||||
]
|
||||
~f:(fun x -> Signal.Expert.handle x handler)
|
||||
;
|
||||
|
||||
|
||||
(* Validate input *)
|
||||
Input.validate ();
|
||||
(* Printf.printf "MD5 : %s\n" (Lazy.force Md5.hash) ; *)
|
||||
@ -191,30 +190,45 @@ let run a d ?q ?s ezfio_filename =
|
||||
|
||||
|
||||
|
||||
let spec =
|
||||
let open Command.Spec in
|
||||
empty
|
||||
+> flag "a" no_arg
|
||||
~doc:(" Add more resources to a running calculation.")
|
||||
+> flag "d" no_arg
|
||||
~doc:(" Start a dataserver process on the local host.")
|
||||
+> flag "q" (optional string)
|
||||
~doc:("<dataserver_addr> Start a qmc process on the local host.")
|
||||
+> flag "s" (optional string)
|
||||
~doc:("<host> Start a qmc process on <host>.")
|
||||
+> anon ("ezfio_file" %: string)
|
||||
|
||||
|
||||
|
||||
let command =
|
||||
Command.basic_spec
|
||||
~summary: "Run a calculation"
|
||||
~readme:(fun () ->
|
||||
"
|
||||
Run QMC=Chem
|
||||
")
|
||||
spec
|
||||
(fun a d q s ezfio_file () -> run a d ?q ?s ezfio_file )
|
||||
let command () =
|
||||
let open Command_line in
|
||||
begin
|
||||
set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command");
|
||||
set_description_doc "Run a calculation";
|
||||
|
||||
[ { short='a' ; long="add" ; opt=Optional ;
|
||||
doc="Add more resources to a running calculation" ;
|
||||
arg=Without_arg ; };
|
||||
|
||||
{ short='d' ; long="data-server" ; opt=Optional ;
|
||||
doc="Start a dataserver process on the local host" ;
|
||||
arg=Without_arg ; };
|
||||
|
||||
{ short='q' ; long="local-qmc" ; opt=Optional ;
|
||||
doc="Start a qmc process on the local host attached to the addres given as an argument" ;
|
||||
arg=With_arg "<string>" ; };
|
||||
|
||||
{ short='s' ; long="remote-qmc" ; opt=Optional ;
|
||||
doc="Start a qmc process on the remote host as an argument" ;
|
||||
arg=With_arg "<string>" ; };
|
||||
|
||||
anonymous "EZFIO_DIR" Mandatory "EZFIO directory";
|
||||
]
|
||||
|> set_specs
|
||||
end;
|
||||
|
||||
let a = Command_line.get_bool "add" in
|
||||
let d = Command_line.get_bool "data-server" in
|
||||
let q = Command_line.get "local-qmc" in
|
||||
let s = Command_line.get "remote-qmc" in
|
||||
|
||||
let ezfio_file =
|
||||
match Command_line.anon_args () with
|
||||
| ezfio_file :: [] -> ezfio_file
|
||||
| _ -> (Command_line.help () ; failwith "Inconsistent command line")
|
||||
in
|
||||
|
||||
run a d ?q ?s ezfio_file
|
||||
|
||||
|
||||
|
||||
|
@ -1,24 +1,23 @@
|
||||
open Core
|
||||
|
||||
|
||||
let run ezfio_filename =
|
||||
Qputils.set_ezfio_filename ezfio_filename;
|
||||
Status.write Status.Stopping
|
||||
|
||||
let command () =
|
||||
let open Command_line in
|
||||
begin
|
||||
set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command");
|
||||
set_description_doc "Stop a running calculation";
|
||||
[ anonymous "EZFIO_DIR" Mandatory "EZFIO directory" ]
|
||||
|> set_specs
|
||||
end;
|
||||
|
||||
let spec =
|
||||
let open Command.Spec in
|
||||
empty
|
||||
+> anon ("ezfio_file" %: string)
|
||||
let ezfio_file =
|
||||
match Command_line.anon_args () with
|
||||
| ezfio_file :: [] -> ezfio_file
|
||||
| _ -> (Command_line.help () ; failwith "Inconsistent command line")
|
||||
in
|
||||
|
||||
let command =
|
||||
Command.basic_spec
|
||||
~summary: "Stop a running calculation"
|
||||
~readme:(fun () ->
|
||||
"
|
||||
Stop a running calculation
|
||||
")
|
||||
spec
|
||||
(fun ezfio_file () -> run ezfio_file )
|
||||
run ezfio_file
|
||||
|
||||
|
||||
|
@ -1,27 +1,26 @@
|
||||
open Core
|
||||
|
||||
let split_re =
|
||||
Str.regexp " +"
|
||||
|
||||
|
||||
let split s =
|
||||
String.strip s
|
||||
String.trim s
|
||||
|> Str.split split_re
|
||||
|
||||
|
||||
let set_ezfio_filename ezfio_filename =
|
||||
let () =
|
||||
if (not (Sys.file_exists_exn ezfio_filename)) then
|
||||
if (not (Sys.file_exists ezfio_filename)) then
|
||||
failwith (ezfio_filename^" does not exist")
|
||||
in
|
||||
let () =
|
||||
match (Sys.is_directory ezfio_filename) with
|
||||
| `Yes -> Ezfio.set_file ezfio_filename ;
|
||||
| _ -> failwith ("Error : "^ezfio_filename^" is not a directory")
|
||||
if Sys.file_exists ezfio_filename && Sys.is_directory ezfio_filename then
|
||||
Ezfio.set_file ezfio_filename
|
||||
else
|
||||
failwith ("Error : "^ezfio_filename^" is not a directory")
|
||||
in
|
||||
let dir, result =
|
||||
Filename.realpath ezfio_filename
|
||||
|> Filename.split
|
||||
Filename.dirname ezfio_filename,
|
||||
Filename.basename ezfio_filename
|
||||
in
|
||||
Unix.chdir dir ;
|
||||
Ezfio.set_file result
|
||||
@ -35,13 +34,18 @@ let ezfio_filename = lazy (
|
||||
match f with
|
||||
| "EZFIO_File" ->
|
||||
begin
|
||||
if (Array.length Sys.argv = 1) then
|
||||
let args =
|
||||
Command_line.anon_args ()
|
||||
|> Array.of_list
|
||||
in
|
||||
if (Array.length args < 1) then
|
||||
failwith "Error : EZFIO directory not specified on the command line\n";
|
||||
Sys.argv.(1)
|
||||
args.(0)
|
||||
end
|
||||
| f -> f
|
||||
in
|
||||
set_ezfio_filename full_path;
|
||||
|
||||
!Ezfio.ezfio_filename
|
||||
)
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
open Core
|
||||
open Qptypes
|
||||
|
||||
type t =
|
||||
@ -26,7 +25,7 @@ module Skewness: sig
|
||||
val to_string : t -> string
|
||||
end = struct
|
||||
type t = float
|
||||
let to_string = Float.to_string
|
||||
let to_string = string_of_float
|
||||
let to_float x = x
|
||||
let of_float x = x
|
||||
end
|
||||
@ -38,7 +37,7 @@ module Kurtosis: sig
|
||||
val to_string : t -> string
|
||||
end = struct
|
||||
type t = float
|
||||
let to_string = Float.to_string
|
||||
let to_string = string_of_float
|
||||
let to_float x = x
|
||||
let of_float x = x
|
||||
end
|
||||
@ -64,7 +63,7 @@ end = struct
|
||||
(x -. mu) *. ( x -. mu) /. sigma2
|
||||
in
|
||||
let pi =
|
||||
Float.acos (-1.)
|
||||
acos (-1.)
|
||||
in
|
||||
let c =
|
||||
1. /. (sqrt (sigma2 *. (pi +. pi)))
|
||||
@ -74,20 +73,35 @@ end = struct
|
||||
end
|
||||
|
||||
|
||||
let hashtbl_to_alist table =
|
||||
Hashtbl.fold (fun k v a -> (k,v) :: a) table []
|
||||
|
||||
let hashtbl_change table key f =
|
||||
let elt =
|
||||
try
|
||||
Some (Hashtbl.find table key)
|
||||
with
|
||||
| Not_found -> None
|
||||
in
|
||||
let new_elt = f elt in
|
||||
match new_elt with
|
||||
| None -> Hashtbl.remove table key
|
||||
| Some value -> Hashtbl.replace table key value
|
||||
|
||||
|
||||
(** Build from raw data. Range values are given in percent. *)
|
||||
let of_raw_data ?(locked=true) ~range property =
|
||||
let data =
|
||||
Block.raw_data ~locked ()
|
||||
|> List.filter ~f:(fun x -> x.Block.property = property)
|
||||
|> List.filter (fun x -> x.Block.property = property)
|
||||
in
|
||||
|
||||
let data_in_range rmin rmax =
|
||||
|
||||
let total_weight =
|
||||
List.fold_left data ~init:0. ~f:(fun accu x ->
|
||||
List.fold_left (fun accu x ->
|
||||
(Weight.to_float x.Block.weight) +. accu
|
||||
)
|
||||
) 0. data
|
||||
in
|
||||
|
||||
let wmin, wmax =
|
||||
@ -96,7 +110,7 @@ let of_raw_data ?(locked=true) ~range property =
|
||||
in
|
||||
|
||||
let (_, new_data) =
|
||||
List.fold_left data ~init:(0.,[]) ~f:(fun (wsum, l) x ->
|
||||
List.fold_left (fun (wsum, l) x ->
|
||||
if (wsum > wmax) then
|
||||
(wsum,l)
|
||||
else
|
||||
@ -109,7 +123,7 @@ let of_raw_data ?(locked=true) ~range property =
|
||||
else
|
||||
(wsum_new, l)
|
||||
end
|
||||
)
|
||||
) (0.,[]) data
|
||||
in
|
||||
List.rev new_data
|
||||
in
|
||||
@ -127,13 +141,13 @@ let of_raw_data ?(locked=true) ~range property =
|
||||
let average { property ; data } =
|
||||
if Property.is_scalar property then
|
||||
let (num,denom) =
|
||||
List.fold ~init:(0., 0.) ~f:(fun (an, ad) x ->
|
||||
List.fold_left (fun (an, ad) x ->
|
||||
let num =
|
||||
(Weight.to_float x.Block.weight) *. (Sample.to_float x.Block.value)
|
||||
and den =
|
||||
(Weight.to_float x.Block.weight)
|
||||
in (an +. num, ad +. den)
|
||||
) data
|
||||
) (0., 0.) data
|
||||
in
|
||||
num /. denom
|
||||
|> Average.of_float
|
||||
@ -144,20 +158,18 @@ let average { property ; data } =
|
||||
| x :: tl -> Sample.dimension x.Block.value
|
||||
in
|
||||
let (num,denom) =
|
||||
List.fold ~init:(Array.create ~len:dim 0. , 0.) ~f:(fun (an, ad) x ->
|
||||
List.fold_left (fun (an, ad) x ->
|
||||
let num =
|
||||
Array.map (Sample.to_float_array x.Block.value) ~f:(fun y ->
|
||||
(Weight.to_float x.Block.weight) *. y)
|
||||
Array.map (fun y -> (Weight.to_float x.Block.weight) *. y)
|
||||
(Sample.to_float_array x.Block.value)
|
||||
and den = (Weight.to_float x.Block.weight)
|
||||
in (
|
||||
Array.mapi an ~f:(fun i y -> y +. num.(i)) ,
|
||||
ad +. den)
|
||||
) data
|
||||
in ( Array.mapi (fun i y -> y +. num.(i)) an , ad +. den)
|
||||
) (Array.make dim 0. , 0.) data
|
||||
in
|
||||
let denom_inv =
|
||||
1. /. denom
|
||||
in
|
||||
Array.map num ~f:(fun x -> x *. denom_inv)
|
||||
Array.map (fun x -> x *. denom_inv) num
|
||||
|> Average.of_float_array ~dim
|
||||
|
||||
|
||||
@ -166,10 +178,10 @@ let average { property ; data } =
|
||||
|
||||
(** Compute sum (for CPU/Wall time) *)
|
||||
let sum { property ; data } =
|
||||
List.fold data ~init:0. ~f:(fun accu x ->
|
||||
List.fold_left (fun accu x ->
|
||||
let num = (Weight.to_float x.Block.weight) *. (Sample.to_float x.Block.value)
|
||||
in accu +. num
|
||||
)
|
||||
) 0. data
|
||||
|
||||
|
||||
|
||||
@ -181,7 +193,7 @@ let ave_error { property ; data } =
|
||||
begin
|
||||
if (n > 0.) then
|
||||
( Average.of_float (sum /. ansum),
|
||||
Some (Error.of_float (sqrt ( Float.abs ( avsq /.( ansum *. n)))) ))
|
||||
Some (Error.of_float (sqrt ( abs_float ( avsq /.( ansum *. n)))) ))
|
||||
else
|
||||
( Average.of_float (sum /. ansum), None)
|
||||
end
|
||||
@ -220,10 +232,10 @@ let ave_error { property ; data } =
|
||||
in
|
||||
|
||||
if (Property.is_scalar property) then
|
||||
List.map data ~f:(fun x ->
|
||||
List.map (fun x ->
|
||||
(Sample.to_float x.Block.value,
|
||||
Weight.to_float x.Block.weight)
|
||||
)
|
||||
) data
|
||||
|> ave_error_scalar
|
||||
else
|
||||
match data with
|
||||
@ -234,22 +246,22 @@ let ave_error { property ; data } =
|
||||
|> Sample.dimension
|
||||
in
|
||||
let result =
|
||||
Array.init dim ~f:(fun idx ->
|
||||
List.map list_of_samples ~f:(fun x ->
|
||||
Array.init dim (fun idx ->
|
||||
List.map (fun x ->
|
||||
(Sample.to_float ~idx x.Block.value,
|
||||
Weight.to_float x.Block.weight)
|
||||
)
|
||||
) list_of_samples
|
||||
|> ave_error_scalar
|
||||
)
|
||||
in
|
||||
( Array.map result ~f:(fun (x,_) -> Average.to_float x)
|
||||
( Array.map (fun (x,_) -> Average.to_float x) result
|
||||
|> Average.of_float_array ~dim ,
|
||||
if (Array.length result < 2) then
|
||||
None
|
||||
else
|
||||
Some (Array.map result ~f:(function
|
||||
Some (Array.map (function
|
||||
| (_,Some y) -> Error.to_float y
|
||||
| (_,None) -> 0.)
|
||||
| (_,None) -> 0.) result
|
||||
|> Average.of_float_array ~dim)
|
||||
)
|
||||
|
||||
@ -258,14 +270,17 @@ let ave_error { property ; data } =
|
||||
|
||||
(** Fold function for block values *)
|
||||
let fold_blocks ~f { property ; data } =
|
||||
let init = match List.hd data with
|
||||
| None -> 0.
|
||||
| Some block -> Sample.to_float block.Block.value
|
||||
let init =
|
||||
try
|
||||
let block = List.hd data in
|
||||
Sample.to_float block.Block.value
|
||||
with
|
||||
| Failure _ -> 0.
|
||||
in
|
||||
List.fold_left data ~init:init ~f:(fun accu block ->
|
||||
List.fold_left (fun accu block ->
|
||||
let x = Sample.to_float block.Block.value
|
||||
in f accu x
|
||||
)
|
||||
) init data
|
||||
|
||||
|
||||
|
||||
@ -288,7 +303,7 @@ let convergence { property ; data } =
|
||||
in
|
||||
let accu =
|
||||
if (n > 0.) then
|
||||
(sum /. ansum, sqrt ( Float.abs ( avsq /.( ansum *. n))))::accu
|
||||
(sum /. ansum, sqrt ( abs_float ( avsq /.( ansum *. n))))::accu
|
||||
else
|
||||
(sum /. ansum, 0.)::accu
|
||||
in
|
||||
@ -347,13 +362,13 @@ let max_block =
|
||||
let create_hash ~create_key ?(update_block_id=(fun x->x))
|
||||
?(update_value=(fun wc vc wb vb sw -> (wc *. vc +. wb *. vb) /. sw) )
|
||||
?(update_weight=(fun wc wb -> wc +. wb) ) t =
|
||||
let table = String.Table.create ()
|
||||
let table = Hashtbl.create 63
|
||||
in
|
||||
List.iter t.data ~f:(fun block ->
|
||||
List.iter (fun block ->
|
||||
let key = create_key block
|
||||
in
|
||||
let open Block in
|
||||
Hashtbl.change table key (function
|
||||
hashtbl_change table key (function
|
||||
| Some current ->
|
||||
let wc, wb =
|
||||
Weight.to_float current.weight,
|
||||
@ -384,7 +399,7 @@ let create_hash ~create_key ?(update_block_id=(fun x->x))
|
||||
{ property = current.property ;
|
||||
weight = Weight.of_float sw ;
|
||||
value =
|
||||
Array.init dim ~f:(fun i -> update_value wc vc.(i) wb vb.(i) sw)
|
||||
Array.init dim (fun i -> update_value wc vc.(i) wb vb.(i) sw)
|
||||
|> Sample.of_float_array ~dim ;
|
||||
block_id = update_block_id block.block_id;
|
||||
pid = block.pid ;
|
||||
@ -399,7 +414,7 @@ let create_hash ~create_key ?(update_block_id=(fun x->x))
|
||||
compute_node = block.compute_node;
|
||||
}
|
||||
)
|
||||
);
|
||||
) t.data ;
|
||||
table
|
||||
|
||||
|
||||
@ -409,12 +424,12 @@ let merge ~create_key ?update_block_id ?update_value ?update_weight t =
|
||||
let table = create_hash ~create_key ?update_block_id ?update_value ?update_weight t
|
||||
in
|
||||
{ property = t.property ;
|
||||
data = Hashtbl.to_alist table
|
||||
|> List.sort ~cmp:(fun x y ->
|
||||
data = hashtbl_to_alist table
|
||||
|> List.sort (fun x y ->
|
||||
if (x>y) then 1
|
||||
else if (x<y) then -1
|
||||
else 0)
|
||||
|> List.map ~f:(fun (x,y) -> y)
|
||||
|> List.map (fun (x,y) -> y)
|
||||
}
|
||||
|
||||
|
||||
@ -440,7 +455,7 @@ let merge_per_compute_node_and_pid =
|
||||
~create_key:(fun block ->
|
||||
Printf.sprintf "%s %10.10d"
|
||||
(Compute_node.to_string block.Block.compute_node)
|
||||
(Pid.to_int block.Block.pid) )
|
||||
(block.Block.pid) )
|
||||
|
||||
|
||||
|
||||
@ -466,7 +481,7 @@ let error_x_over_y = function
|
||||
in
|
||||
let avcu = ref !avbl
|
||||
in
|
||||
List.iter tail ~f:(fun (x,w) ->
|
||||
List.iter (fun (x,w) ->
|
||||
avcu0 := !avsum /. !ansum;
|
||||
ansum := !ansum +. w;
|
||||
avsum := !avsum +. x;
|
||||
@ -476,9 +491,9 @@ let error_x_over_y = function
|
||||
else ();
|
||||
avsq := !avsq +. (1. -. w /. !ansum) *. (!avbl -. !avcu0) *. (!avbl -. !avcu0) *. w;
|
||||
n := !n +. 1.
|
||||
);
|
||||
) tail ;
|
||||
let arg =
|
||||
Float.abs (!avsq /.(!ansum *. (!n -. 1.)))
|
||||
abs_float (!avsq /.(!ansum *. (!n -. 1.)))
|
||||
in
|
||||
let error =
|
||||
sqrt arg
|
||||
@ -490,7 +505,7 @@ let error_x_over_y = function
|
||||
(** Create float, variable operators *)
|
||||
let one_variable_operator ~update_value p f =
|
||||
{ p with
|
||||
data = List.map ~f:(fun b -> { b with
|
||||
data = List.map (fun b -> { b with
|
||||
Block.value = Sample.of_float (update_value (Sample.to_float b.Block.value) ) }
|
||||
) p.data }
|
||||
|
||||
@ -515,7 +530,7 @@ let two_variable_operator ~update_value p1 p2 =
|
||||
Printf.sprintf "%s %10.10d %10.10d"
|
||||
(Compute_node.to_string block.Block.compute_node)
|
||||
(Block_id.to_int block.Block.block_id)
|
||||
(Pid.to_int block.Block.pid) )
|
||||
(block.Block.pid) )
|
||||
~update_weight:(fun wc wb -> wc )
|
||||
{ property = p1.property ;
|
||||
data = List.concat [ p1.data ; p2.data ] }
|
||||
@ -550,18 +565,18 @@ let compress =
|
||||
|
||||
(** Last value on each compute node (for wall_time) *)
|
||||
let max_value_per_compute_node t =
|
||||
let table = String.Table.create ()
|
||||
let table = Hashtbl.create 63
|
||||
in
|
||||
let create_key block =
|
||||
Printf.sprintf "%s %10.10d"
|
||||
(Compute_node.to_string block.Block.compute_node)
|
||||
(Pid.to_int block.Block.pid)
|
||||
(block.Block.pid)
|
||||
in
|
||||
List.iter t.data ~f:(fun block ->
|
||||
List.iter (fun block ->
|
||||
let key = create_key block
|
||||
in
|
||||
let open Block in
|
||||
Hashtbl.change table key (function
|
||||
hashtbl_change table key (function
|
||||
| Some current ->
|
||||
let vc = Sample.to_float current.value
|
||||
and vb = Sample.to_float block.value
|
||||
@ -572,14 +587,14 @@ let max_value_per_compute_node t =
|
||||
Some block
|
||||
| None -> Some block
|
||||
)
|
||||
);
|
||||
) t.data ;
|
||||
{ property = t.property ;
|
||||
data = Hashtbl.to_alist table
|
||||
|> List.sort ~cmp:(fun x y ->
|
||||
data = hashtbl_to_alist table
|
||||
|> List.sort (fun x y ->
|
||||
if (x>y) then 1
|
||||
else if (x<y) then -1
|
||||
else 0)
|
||||
|> List.map ~f:(fun (x,y) -> y)
|
||||
|> List.map (fun (x,y) -> y)
|
||||
}
|
||||
|
||||
|
||||
@ -588,8 +603,8 @@ let max_value_per_compute_node t =
|
||||
(** String representation *)
|
||||
let to_string p =
|
||||
match p.property with
|
||||
| Property.Cpu -> Printf.sprintf "%s" (Time.Span.to_string (Time.Span.of_sec (sum p)))
|
||||
| Property.Wall -> Printf.sprintf "%s" (Time.Span.to_string (Time.Span.of_sec (sum (max_value_per_compute_node p))))
|
||||
| Property.Cpu -> Printf.sprintf "%s" (Time.string_of_sec (sum p))
|
||||
| Property.Wall -> Printf.sprintf "%s" (Time.string_of_sec (sum (max_value_per_compute_node p)))
|
||||
| Property.Accep -> Printf.sprintf "%16.10f" (average p |> Average.to_float)
|
||||
| _ ->
|
||||
begin
|
||||
@ -652,17 +667,33 @@ let compress_files () =
|
||||
Lazy.force dir_name
|
||||
in
|
||||
let files =
|
||||
Sys.ls_dir dir_name
|
||||
|> List.filter ~f:(fun x ->
|
||||
match String.substr_index ~pattern:"locked" x with
|
||||
| Some x -> false
|
||||
| None -> true
|
||||
Sys.readdir dir_name
|
||||
|> Array.to_list
|
||||
|> List.filter (fun x ->
|
||||
try
|
||||
Str.search_backward (Str.regexp "locked") x (String.length x) >= 0
|
||||
with
|
||||
| Not_found -> true
|
||||
)
|
||||
|> List.map ~f:(fun x -> dir_name^x)
|
||||
|> List.map (fun x -> dir_name^x)
|
||||
in
|
||||
|
||||
let out_channel_dir =
|
||||
Filename.temp_dir ~in_dir:(!Ezfio.ezfio_filename ^ "/blocks/") "qmc" ""
|
||||
let rand_num = Random.int 1000000 |> string_of_int in
|
||||
let dirname =
|
||||
Filename.concat !Ezfio.ezfio_filename "blocks"
|
||||
in
|
||||
if not ( Sys.file_exists dirname ) then
|
||||
Unix.mkdir dirname 0o755;
|
||||
let tmp_dir =
|
||||
Filename.concat dirname ("qmc"^rand_num)
|
||||
in
|
||||
try
|
||||
Unix.mkdir tmp_dir 0o755;
|
||||
tmp_dir
|
||||
with _ ->
|
||||
let message = Printf.sprintf "Cannot create temp dir %s" tmp_dir in
|
||||
raise (Sys_error message)
|
||||
in
|
||||
|
||||
let out_channel_name =
|
||||
@ -670,16 +701,17 @@ let compress_files () =
|
||||
Lazy.force Qmcchem_config.hostname
|
||||
and suffix =
|
||||
Unix.getpid ()
|
||||
|> Pid.to_string
|
||||
|> string_of_int
|
||||
in
|
||||
String.concat [ hostname ; "." ; suffix ]
|
||||
String.concat "." [ hostname ; suffix ]
|
||||
in
|
||||
|
||||
let block_channel =
|
||||
Out_channel.create (out_channel_dir ^ out_channel_name)
|
||||
Filename.concat out_channel_dir out_channel_name
|
||||
|> open_out
|
||||
in
|
||||
|
||||
List.iter properties ~f:(fun p ->
|
||||
List.iter (fun p ->
|
||||
let l =
|
||||
match p with
|
||||
| Property.Cpu
|
||||
@ -693,15 +725,16 @@ let compress_files () =
|
||||
of_raw_data ~locked:false ~range:(0.,100.) p
|
||||
|> merge_per_compute_node_and_block_id
|
||||
in
|
||||
List.iter l.data ~f:(fun x ->
|
||||
Out_channel.output_string block_channel (Block.to_string x);
|
||||
Out_channel.output_char block_channel '\n';
|
||||
);
|
||||
);
|
||||
Out_channel.close block_channel;
|
||||
List.iter (fun x ->
|
||||
output_string block_channel (Block.to_string x);
|
||||
output_char block_channel '\n';
|
||||
) l.data
|
||||
) properties ;
|
||||
close_out block_channel;
|
||||
|
||||
List.iter files ~f:Unix.remove ;
|
||||
Unix.rename ~src:(out_channel_dir^out_channel_name) ~dst:(dir_name^out_channel_name);
|
||||
List.iter Unix.unlink files ;
|
||||
Unix.rename (Filename.concat out_channel_dir out_channel_name)
|
||||
(Filename.concat dir_name out_channel_name);
|
||||
Unix.rmdir out_channel_dir
|
||||
|
||||
|
||||
@ -716,20 +749,20 @@ let autocovariance { property ; data } =
|
||||
with { property ; data } -> Array.of_list data
|
||||
in
|
||||
let x_t =
|
||||
Array.map ~f:(fun x -> (Sample.to_float x.Block.value) -. ave) data
|
||||
Array.map (fun x -> (Sample.to_float x.Block.value) -. ave) data
|
||||
in
|
||||
let f i =
|
||||
let denom =
|
||||
if (i > 1) then (Float.of_int i) else 1.
|
||||
if (i > 1) then (float_of_int i) else 1.
|
||||
in
|
||||
let r =
|
||||
Array.sub ~pos:0 ~len:i x_t
|
||||
|> Array.fold ~init:0. ~f:(fun accu x ->
|
||||
accu +. x *. x_t.(i))
|
||||
Array.sub x_t 0 i
|
||||
|> Array.fold_left (fun accu x ->
|
||||
accu +. x *. x_t.(i)) 0.
|
||||
in
|
||||
r /. denom
|
||||
in
|
||||
Array.init ~f (Array.length data)
|
||||
Array.init (Array.length data) f
|
||||
|> Array.to_list
|
||||
|
||||
|
||||
@ -741,7 +774,7 @@ let centered_cumulants { property ; data } =
|
||||
|> Average.to_float
|
||||
in
|
||||
let centered_data =
|
||||
List.map ~f:(fun x ->
|
||||
List.map (fun x ->
|
||||
( (Weight.to_float x.Block.weight),
|
||||
(Sample.to_float x.Block.value) -. ave )
|
||||
)
|
||||
@ -749,20 +782,20 @@ let centered_cumulants { property ; data } =
|
||||
in
|
||||
let var =
|
||||
let (num, denom) =
|
||||
List.fold ~init:(0., 0.) ~f:(fun (a2, ad) (w,x) ->
|
||||
List.fold_left (fun (a2, ad) (w,x) ->
|
||||
let x2 = x *. x
|
||||
in
|
||||
let var = w *. x2
|
||||
and den = w
|
||||
in (a2 +. var, ad +. den)
|
||||
) centered_data
|
||||
) (0., 0.) centered_data
|
||||
in num /. denom
|
||||
in
|
||||
let centered_data =
|
||||
let sigma_inv =
|
||||
1. /. (sqrt var)
|
||||
in
|
||||
List.map ~f:(fun x ->
|
||||
List.map (fun x ->
|
||||
( (Weight.to_float x.Block.weight),
|
||||
( (Sample.to_float x.Block.value) -. ave ) *. sigma_inv )
|
||||
)
|
||||
@ -770,14 +803,14 @@ let centered_cumulants { property ; data } =
|
||||
in
|
||||
let (cum3,cum4) =
|
||||
let (cum3, cum4, denom) =
|
||||
List.fold ~init:(0., 0., 0.) ~f:(fun (a3, a4, ad) (w,x) ->
|
||||
List.fold_left (fun (a3, a4, ad) (w,x) ->
|
||||
let x2 = x *. x
|
||||
in
|
||||
let cum3 = w *. x2 *. x
|
||||
and cum4 = w *. x2 *. x2
|
||||
and den = w
|
||||
in (a3 +. cum3, a4 +. cum4, ad +. den)
|
||||
) centered_data
|
||||
) (0., 0., 0.) centered_data
|
||||
in
|
||||
( cum3 /. denom, cum4 /. denom -. 3. )
|
||||
in
|
||||
@ -796,15 +829,15 @@ let histogram { property ; data } =
|
||||
max -. min
|
||||
and n =
|
||||
List.length data
|
||||
|> Float.of_int
|
||||
|> float_of_int
|
||||
|> sqrt
|
||||
in
|
||||
let delta_x =
|
||||
length /. (n-.1.)
|
||||
and result =
|
||||
Array.init ~f:(fun _ -> 0.) (Int.of_float (n +. 1.))
|
||||
Array.init (int_of_float n + 1) (fun _ -> 0.)
|
||||
in
|
||||
List.iter ~f:(fun x ->
|
||||
List.iter (fun x ->
|
||||
let w =
|
||||
(Weight.to_float x.Block.weight)
|
||||
and x =
|
||||
@ -812,17 +845,17 @@ let histogram { property ; data } =
|
||||
in
|
||||
let i =
|
||||
(x -. min) /. delta_x +. 0.5
|
||||
|> Float.to_int
|
||||
|> int_of_float
|
||||
in
|
||||
result.(i) <- result.(i) +. w
|
||||
) data
|
||||
;
|
||||
let norm =
|
||||
1. /. ( delta_x *. (
|
||||
Array.fold ~init:0. ~f:(fun accu x -> accu +. x) result
|
||||
Array.fold_left (fun accu x -> accu +. x) 0. result
|
||||
) )
|
||||
in
|
||||
Array.mapi ~f:(fun i x -> (min +. (Float.of_int i)*.delta_x, x *. norm) ) result
|
||||
Array.mapi (fun i x -> (min +. (float_of_int i)*.delta_x, x *. norm) ) result
|
||||
|> Array.to_list
|
||||
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
open Core
|
||||
open Sexplib.Std
|
||||
|
||||
type t =
|
||||
| One_dimensional of float
|
||||
| Multidimensional of (float array * int)
|
||||
[@ deriving sexp]
|
||||
[@@deriving sexp]
|
||||
|
||||
let dimension = function
|
||||
| One_dimensional _ -> 1
|
||||
@ -38,9 +38,10 @@ let of_float_array ~dim x =
|
||||
| _ -> Multidimensional (x, dim)
|
||||
|
||||
let to_string = function
|
||||
| One_dimensional x -> Float.to_string x
|
||||
| One_dimensional x -> string_of_float x
|
||||
| Multidimensional (x,_) ->
|
||||
Array.map x ~f:Float.to_string
|
||||
|> String.concat_array ~sep:" "
|
||||
Array.map string_of_float x
|
||||
|> Array.to_list
|
||||
|> String.concat " "
|
||||
|> Printf.sprintf "%s"
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
open Core
|
||||
|
||||
type t [@@deriving sexp]
|
||||
val to_float : ?idx:int -> t -> float
|
||||
val to_float_array : t -> float array
|
||||
|
@ -1,5 +1,3 @@
|
||||
open Core
|
||||
|
||||
type t =
|
||||
| SGE
|
||||
| PBS
|
||||
@ -18,12 +16,10 @@ let to_string = function
|
||||
let find () =
|
||||
let scheduler =
|
||||
[ "SLURM_NODELIST" ; "PE_HOSTFILE" ; "PBS_NODEFILE" ]
|
||||
|> List.map ~f:(function x ->
|
||||
match (Sys.getenv x) with
|
||||
| Some _ -> x
|
||||
| None -> ""
|
||||
|> List.map (function x ->
|
||||
try Some (Sys.getenv x) with
|
||||
| Not_found -> None
|
||||
)
|
||||
|> List.filter ~f:(function x -> x <> "")
|
||||
|> List.hd
|
||||
in
|
||||
let result =
|
||||
|
160
ocaml/String_ext.ml
Normal file
160
ocaml/String_ext.ml
Normal file
@ -0,0 +1,160 @@
|
||||
include String
|
||||
|
||||
(** Split a string on a given character *)
|
||||
let split ?(on=' ') str =
|
||||
split_on_char on str
|
||||
|
||||
|
||||
(** Strip blanks on the left of a string *)
|
||||
let ltrim s =
|
||||
let rec do_work s l =
|
||||
match s.[0] with
|
||||
| '\n'
|
||||
| ' ' -> do_work (sub s 1 (l-1)) (l-1)
|
||||
| _ -> s
|
||||
in
|
||||
let l =
|
||||
length s
|
||||
in
|
||||
if (l > 0) then
|
||||
do_work s l
|
||||
else
|
||||
s
|
||||
|
||||
(** Strip blanks on the right of a string *)
|
||||
let rtrim s =
|
||||
let rec do_work s l =
|
||||
let newl =
|
||||
l-1
|
||||
in
|
||||
match s.[newl] with
|
||||
| '\n'
|
||||
| ' ' -> do_work (sub s 0 (newl)) (newl)
|
||||
| _ -> s
|
||||
in
|
||||
let l =
|
||||
length s
|
||||
in
|
||||
if (l > 0) then
|
||||
do_work s l
|
||||
else
|
||||
s
|
||||
|
||||
|
||||
(** Strip blanks on the right and left of a string *)
|
||||
let strip = String.trim
|
||||
|
||||
|
||||
(** Split a string in two pieces when a character is found the 1st time from the left *)
|
||||
let lsplit2_exn ?(on=' ') s =
|
||||
let length =
|
||||
String.length s
|
||||
in
|
||||
let rec do_work i =
|
||||
if (i = length) then
|
||||
begin
|
||||
raise Not_found
|
||||
end
|
||||
else if (s.[i] = on) then
|
||||
( String.sub s 0 i,
|
||||
String.sub s (i+1) (length-i-1) )
|
||||
else
|
||||
do_work (i+1)
|
||||
in
|
||||
do_work 0
|
||||
|
||||
|
||||
(** Split a string in two pieces when a character is found the 1st time from the right *)
|
||||
let rsplit2_exn ?(on=' ') s =
|
||||
let length =
|
||||
String.length s
|
||||
in
|
||||
let rec do_work i =
|
||||
if (i = -1) then
|
||||
begin
|
||||
raise Not_found
|
||||
end
|
||||
else if (s.[i] = on) then
|
||||
( String.sub s 0 i,
|
||||
String.sub s (i+1) (length-i-1) )
|
||||
else
|
||||
do_work (i-1)
|
||||
in
|
||||
do_work (length-1)
|
||||
|
||||
|
||||
let lsplit2 ?(on=' ') s =
|
||||
try
|
||||
Some (lsplit2_exn ~on s)
|
||||
with
|
||||
| Not_found -> None
|
||||
|
||||
|
||||
let rsplit2 ?(on=' ') s =
|
||||
try
|
||||
Some (rsplit2_exn ~on s)
|
||||
with
|
||||
| Not_found -> None
|
||||
|
||||
|
||||
let to_list s =
|
||||
Array.init (String.length s) (fun i -> s.[i])
|
||||
|> Array.to_list
|
||||
|
||||
|
||||
let of_list l =
|
||||
let a = Array.of_list l in
|
||||
String.init (Array.length a) (fun i -> a.(i))
|
||||
|
||||
let rev s =
|
||||
to_list s
|
||||
|> List.rev
|
||||
|> of_list
|
||||
|
||||
let fold ~init ~f s =
|
||||
to_list s
|
||||
|> List.fold_left f init
|
||||
|
||||
|
||||
let is_prefix ~prefix s =
|
||||
let len =
|
||||
String.length prefix
|
||||
in
|
||||
if len > String.length s then
|
||||
false
|
||||
else
|
||||
prefix = String.sub s 0 len
|
||||
|
||||
|
||||
let of_char c =
|
||||
String.make 1 c
|
||||
|
||||
let tr ~target ~replacement s =
|
||||
String.map (fun c -> if c = target then replacement else c) s
|
||||
|
||||
|
||||
let substr_index ?(pos=0) ~pattern s =
|
||||
try
|
||||
let regexp =
|
||||
Str.regexp pattern
|
||||
in
|
||||
Some (Str.search_forward regexp s pos)
|
||||
with Not_found -> None
|
||||
|
||||
|
||||
let substr_replace_all ~pattern ~with_ s =
|
||||
let regexp =
|
||||
Str.regexp pattern
|
||||
in
|
||||
Str.global_replace regexp with_ s
|
||||
|
||||
|
||||
let input_lines ic =
|
||||
let rec aux ic accu =
|
||||
try
|
||||
aux ic ((input_line ic)::accu)
|
||||
with
|
||||
| End_of_file -> List.rev accu
|
||||
in
|
||||
aux ic []
|
||||
|
50
ocaml/Time.ml
Normal file
50
ocaml/Time.ml
Normal file
@ -0,0 +1,50 @@
|
||||
let of_sec s =
|
||||
Unix.gmtime s
|
||||
|
||||
let to_sec t =
|
||||
let sec = t.Unix.tm_sec
|
||||
and min = t.Unix.tm_min
|
||||
and hour = t.Unix.tm_hour
|
||||
and mday = t.Unix.tm_mday
|
||||
in
|
||||
sec +
|
||||
min * 60 +
|
||||
hour * 60 * 60 +
|
||||
(mday-1) * 60 * 60 * 24
|
||||
|
||||
let string_of_t t =
|
||||
let mday = t.Unix.tm_mday - 1 in
|
||||
let sec = t.Unix.tm_sec
|
||||
and min = t.Unix.tm_min
|
||||
and hour = t.Unix.tm_hour + 24*mday
|
||||
in
|
||||
Printf.sprintf "%2d:%2.2d:%2.2d" hour min sec
|
||||
|
||||
let string_of_date t =
|
||||
let year = 1900 + t.Unix.tm_year in
|
||||
let mon = t.Unix.tm_mon in
|
||||
let mday = t.Unix.tm_mday in
|
||||
let sec = t.Unix.tm_sec
|
||||
and min = t.Unix.tm_min
|
||||
and hour = t.Unix.tm_hour
|
||||
in
|
||||
let month =
|
||||
match mon with
|
||||
| 0 -> "Jan" | 1 -> "Feb" | 2 -> "Mar" | 3 -> "Apr"
|
||||
| 4 -> "May" | 5 -> "Jun" | 6 -> "Jul" | 7 -> "Aug"
|
||||
| 8 -> "Sep" | 9 -> "Oct" | 10 -> "Nov" | 11 -> "Dec"
|
||||
| _ -> assert false
|
||||
in
|
||||
Printf.sprintf "%2d %3s %4d - %2d:%2.2d:%2.2d" mday month year hour min sec
|
||||
|
||||
|
||||
let string_of_now () =
|
||||
Unix.gettimeofday ()
|
||||
|> Unix.localtime
|
||||
|> string_of_date
|
||||
|
||||
|
||||
let string_of_sec s =
|
||||
of_sec s
|
||||
|> string_of_t
|
||||
|
@ -1,18 +1,16 @@
|
||||
open Core
|
||||
|
||||
let _list = ref [] ;;
|
||||
let _running = ref false;;
|
||||
let _threads = ref [] ;;
|
||||
let _list = ref []
|
||||
let _running = ref false
|
||||
let _threads = ref []
|
||||
|
||||
(** Kill the current process and all children *)
|
||||
let kill () =
|
||||
let kill pid =
|
||||
Signal.send_i Signal.int (`Pid pid);
|
||||
Printf.printf "Killed %d\n%!" (Pid.to_int pid)
|
||||
Unix.kill pid Sys.sigkill;
|
||||
Printf.printf "Killed %d\n%!" pid
|
||||
in
|
||||
List.iter ~f:kill (!_list);
|
||||
List.iter kill (!_list);
|
||||
exit 1
|
||||
;;
|
||||
|
||||
|
||||
|
||||
(** Start watchdog *)
|
||||
@ -25,14 +23,11 @@ let start () =
|
||||
_running := true;
|
||||
|
||||
let pause () =
|
||||
Time.Span.of_sec 1.
|
||||
|> Time.pause
|
||||
Unix.sleep 1
|
||||
in
|
||||
|
||||
let pid_is_running pid =
|
||||
match (Sys.file_exists ("/proc/"^(Pid.to_string pid)^"/stat")) with
|
||||
| `No | `Unknown -> false
|
||||
| `Yes -> true
|
||||
Sys.file_exists ("/proc/"^(string_of_int pid)^"/stat")
|
||||
in
|
||||
|
||||
let f () =
|
||||
@ -41,13 +36,13 @@ let start () =
|
||||
pause () ;
|
||||
|
||||
(*DEBUG
|
||||
List.iter (!_list) ~f:(fun x -> Printf.printf "%d\n%!" (Pid.to_int x));
|
||||
List.iter (fun x -> Printf.printf "%d\n%!" x) (!_list) ;
|
||||
*)
|
||||
|
||||
let continue () =
|
||||
List.fold_left (!_list) ~init:true ~f:(
|
||||
fun accu x -> accu && (pid_is_running x)
|
||||
)
|
||||
List.fold_left
|
||||
( fun accu x -> accu && (pid_is_running x))
|
||||
true (!_list)
|
||||
in
|
||||
if ( not (continue ()) ) then
|
||||
kill ()
|
||||
@ -55,7 +50,7 @@ let start () =
|
||||
in
|
||||
_threads := ( (Thread.create f) () ) :: (!_threads)
|
||||
end
|
||||
;;
|
||||
|
||||
|
||||
(** Stop watchdog *)
|
||||
let stop () =
|
||||
@ -63,14 +58,14 @@ let stop () =
|
||||
_running := false
|
||||
else
|
||||
failwith "Watchdog error: Already stopped"
|
||||
;;
|
||||
|
||||
|
||||
(** Add a PID to tracking *)
|
||||
let add pid =
|
||||
if (not !_running) then
|
||||
start ();
|
||||
_list := pid :: (!_list)
|
||||
;;
|
||||
|
||||
|
||||
(** Remove a PID from tracking *)
|
||||
let del pid =
|
||||
@ -87,27 +82,26 @@ let del pid =
|
||||
match (!_list) with
|
||||
| [] -> if (!_running) then stop ()
|
||||
| _ -> ()
|
||||
;;
|
||||
|
||||
|
||||
(** Fork and exec a new process *)
|
||||
let fork_exec ~prog ~argv () =
|
||||
let fork_exec ~prog ~args () =
|
||||
let pid =
|
||||
Unix.fork_exec ~prog ~argv ()
|
||||
match Unix.fork () with
|
||||
| 0 -> Unix.execvp prog args
|
||||
| pid -> pid
|
||||
in
|
||||
|
||||
let f () =
|
||||
add pid;
|
||||
let success =
|
||||
match (Unix.waitpid pid) with
|
||||
| Core_kernel.Std.Result.Ok () -> true
|
||||
| Core_kernel.Std.Result.Error (`Exit_non_zero n) ->
|
||||
( Printf.printf "PID %d exited with code %d\n%!"
|
||||
(Pid.to_int pid) n ;
|
||||
match (Unix.waitpid [] pid) with
|
||||
| pid , Unix.WEXITED n -> true
|
||||
| pid , Unix.WSIGNALED n ->
|
||||
( Printf.printf "PID %d killed with signal %d\n%!" pid n;
|
||||
false )
|
||||
| Core_kernel.Std.Result.Error (`Signal n) ->
|
||||
( Printf.printf "PID %d killed with signal %d (%s)\n%!"
|
||||
(Pid.to_int pid) (Signal.to_system_int n)
|
||||
(Signal.to_string n) ;
|
||||
| pid , Unix.WSTOPPED n ->
|
||||
( Printf.printf "PID %d stopped with signal %d\n%!" pid n;
|
||||
false )
|
||||
in
|
||||
del pid ;
|
||||
@ -116,11 +110,11 @@ let fork_exec ~prog ~argv () =
|
||||
in
|
||||
_threads := ( (Thread.create f) () ) :: (!_threads);
|
||||
pid
|
||||
;;
|
||||
|
||||
|
||||
(** Wait for threads to finish *)
|
||||
let join () =
|
||||
(* if (!_running) then stop (); *)
|
||||
List.iter ~f:Thread.join (!_threads);
|
||||
List.iter Thread.join (!_threads);
|
||||
assert (not !_running)
|
||||
;;
|
||||
|
||||
|
6
ocaml/_tags
Normal file
6
ocaml/_tags
Normal file
@ -0,0 +1,6 @@
|
||||
true: package(cryptokit,zmq,str,sexplib,ppx_sexp_conv,ppx_deriving,getopt)
|
||||
true: thread
|
||||
false: profile
|
||||
<*byte> : linkdep(c_bindings.o), custom
|
||||
<*.native>: linkdep(c_bindings.o)
|
||||
|
@ -1,84 +0,0 @@
|
||||
MAIN=qmcchem
|
||||
# Main program to build
|
||||
|
||||
PACKAGES=-package core,cryptokit,str,zmq
|
||||
#,ppx_sexp_conv
|
||||
# Required opam packages, for example:
|
||||
# PACKAGES=-package core,sexplib.syntax
|
||||
|
||||
THREAD=-thread
|
||||
# If you need threding support, use:
|
||||
# THREAD=-thread
|
||||
|
||||
SYNTAX=
|
||||
# If you need pre-processing, use:
|
||||
# SYNTAX=-syntax camlp4o
|
||||
|
||||
OCAMLC_FLAGS=-g -warn-error A
|
||||
# Flags to give to ocamlc, for example:
|
||||
# OCAMLC_FLAGS=-g -warn-error A
|
||||
|
||||
LINK_FLAGS=
|
||||
# Flags to give to the linker, for example:
|
||||
# LINK_FLAGS=-cclib '-Wl,-rpath=../lib,--enable-new-dtags'
|
||||
|
||||
GENERATED_NINJA=generated.ninja
|
||||
# Name of the auto-generated ninja file
|
||||
|
||||
rule run_ninja
|
||||
command = ../scripts/compile_ocaml.sh $target
|
||||
description = Compiling OCaml executables
|
||||
pool = console
|
||||
|
||||
rule run_ninja_ocaml
|
||||
command = ../scripts/compile_ocaml_dep.sh
|
||||
description = Finding dependencies in OCaml files
|
||||
|
||||
rule run_clean
|
||||
command = ninja -f $GENERATED_NINJA -t clean ; rm -f $GENERATED_NINJA rm -f *.cmx *.cmi *.o .ls_md5 ; ninja -t clean
|
||||
pool = console
|
||||
description = Cleaning directory
|
||||
|
||||
rule ocamlc
|
||||
command = ocamlfind ocamlc -c $OCAMLC_FLAGS $THREAD $PACKAGES $SYNTAX -o $out $in
|
||||
description = Compiling $in (bytecode)
|
||||
|
||||
rule ocamlopt
|
||||
command = ocamlfind ocamlopt -c $OCAMLC_FLAGS $THREAD $PACKAGES $SYNTAX -o $out $in
|
||||
description = Compiling $in (native)
|
||||
|
||||
rule ocamlc_link
|
||||
command = ocamlfind ocamlc $OCAMLC_FLAGS $THREAD $LINK_FLAGS $PACKAGES $SYNTAX -o $out $in
|
||||
description = Compiling $out (bytecode)
|
||||
|
||||
rule ocamlopt_link
|
||||
command = ocamlfind ocamlopt $OCAMLC_FLAGS $THREAD -linkpkg $PACKAGES $PACKAGES $SYNTAX -o $out $in
|
||||
description = Compiling $out (native)
|
||||
|
||||
rule create_qptypes
|
||||
command = ./$in
|
||||
description = Creating $out
|
||||
|
||||
rule copy
|
||||
command = cp $in $out
|
||||
description = Copying $in to $out
|
||||
|
||||
build always: phony
|
||||
build $GENERATED_NINJA: run_ninja_ocaml | Qptypes.ml ezfio.ml always
|
||||
build ezfio.ml: copy ../EZFIO/Ocaml/ezfio.ml
|
||||
build Qptypes.ml: create_qptypes qptypes_generator | ezfio.ml
|
||||
build qptypes_generator.o qptypes_generator.cmx: ocamlopt qptypes_generator.ml | ezfio.ml
|
||||
build qptypes_generator: ocamlopt_link qptypes_generator.cmx
|
||||
|
||||
build clean: run_clean
|
||||
|
||||
build $MAIN: run_ninja | ezfio.ml Qptypes.ml $GENERATED_NINJA
|
||||
target = $MAIN
|
||||
|
||||
build all: run_ninja | ezfio.ml Qptypes.ml $GENERATED_NINJA
|
||||
target =
|
||||
|
||||
default $MAIN
|
||||
|
||||
|
||||
|
70
ocaml/c_bindings.c
Normal file
70
ocaml/c_bindings.c
Normal file
@ -0,0 +1,70 @@
|
||||
#include <caml/mlvalues.h>
|
||||
#include <caml/memory.h>
|
||||
#include <caml/alloc.h>
|
||||
#include <caml/custom.h>
|
||||
#include <caml/threads.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
||||
/* Adapted from
|
||||
https://github.com/monadbobo/ocaml-core/blob/master/base/core/lib/linux_ext_stubs.c
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
CAMLprim value get_ipv4_address_for_interface(value v_interface)
|
||||
{
|
||||
CAMLparam1(v_interface);
|
||||
struct ifreq ifr;
|
||||
int fd = -1;
|
||||
value res;
|
||||
char* error = NULL;
|
||||
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
ifr.ifr_addr.sa_family = AF_INET;
|
||||
/* [ifr] is already initialized to zero, so it doesn't matter if the
|
||||
incoming string is too long, and [strncpy] fails to add a \0. */
|
||||
strncpy(ifr.ifr_name, String_val(v_interface), IFNAMSIZ - 1);
|
||||
|
||||
caml_enter_blocking_section();
|
||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
if (fd == -1)
|
||||
error = "error: couldn't allocate socket";
|
||||
else {
|
||||
if (ioctl(fd, SIOCGIFADDR, &ifr) < 0)
|
||||
error = "error: ioctl(fd, SIOCGIFADDR, ...) failed";
|
||||
|
||||
(void) close(fd);
|
||||
}
|
||||
|
||||
caml_leave_blocking_section();
|
||||
|
||||
if (error == NULL) {
|
||||
/* This is weird but doing the usual casting causes errors when using
|
||||
* the new gcc on CentOS 6. This solution was picked up on Red Hat's
|
||||
* bugzilla or something. It also works to memcpy a sockaddr into
|
||||
* a sockaddr_in. This is faster hopefully.
|
||||
*/
|
||||
union {
|
||||
struct sockaddr sa;
|
||||
struct sockaddr_in sain;
|
||||
} u;
|
||||
u.sa = ifr.ifr_addr;
|
||||
res = caml_copy_string(inet_ntoa(u.sain.sin_addr));
|
||||
}
|
||||
else
|
||||
res = caml_copy_string(error);
|
||||
CAMLreturn(res);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
13
ocaml/myocamlbuild.ml
Normal file
13
ocaml/myocamlbuild.ml
Normal file
@ -0,0 +1,13 @@
|
||||
open Ocamlbuild_plugin;;
|
||||
|
||||
dispatch begin function
|
||||
| Before_rules ->
|
||||
begin
|
||||
end
|
||||
| After_rules ->
|
||||
begin
|
||||
flag ["ocaml";"compile";"native";"gprof"] (S [ A "-p"]);
|
||||
pdep ["link"] "linkdep" (fun param -> [param]);
|
||||
end
|
||||
| _ -> ()
|
||||
end
|
@ -1,288 +0,0 @@
|
||||
#!/usr/bin/env python2
|
||||
#
|
||||
# Copyright 2015 Anthony Scemama
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# This file can be downloaded here:
|
||||
# https://raw.githubusercontent.com/scemama/ninja_ocaml/master/ninja_ocaml.py
|
||||
#
|
||||
|
||||
"""Build OCaml projects using ninja."""
|
||||
|
||||
__author__ = """Anthony Scemama <scemama@irsamc.ups-tlse.fr>"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
def _help_ ():
|
||||
print """
|
||||
1) Download and install ninja :
|
||||
https://github.com/martine/ninja/releases/latest
|
||||
2) Copy the script into your OCaml project.
|
||||
3) Run the script. It will build a default build.ninja file
|
||||
4) Edit the build.ninja file
|
||||
5) Compile the main target using `ninja`
|
||||
6) Compile all the targets using `ninja all`
|
||||
"""
|
||||
|
||||
def create_generated_ninja():
|
||||
"""Creates the generated.ninja file"""
|
||||
|
||||
# Header
|
||||
PACKAGES=""
|
||||
THREAD=""
|
||||
SYNTAX=""
|
||||
OCAMLC_FLAGS=""
|
||||
GENERATED_NINJA="generated.ninja"
|
||||
with open('build.ninja','r') as f:
|
||||
for line in f:
|
||||
if line.startswith("PACKAGES"):
|
||||
PACKAGES=line.split('=',1)[1].strip()
|
||||
elif line.startswith("THREAD"):
|
||||
THREAD=line.split('=',1)[1].strip()
|
||||
elif line.startswith("SYNTAX"):
|
||||
SYNTAX=line.split('=',1)[1].strip()
|
||||
elif line.startswith("OCAMLC_FLAGS"):
|
||||
OCAMLC_FLAGS=line.split('=',1)[1].strip()
|
||||
elif line.startswith("LINK_FLAGS"):
|
||||
LINK_FLAGS=line.split('=',1)[1].strip()
|
||||
elif line.startswith("GENERATED_NINJA"):
|
||||
GENERATED_NINJA=line.split('=',1)[1].strip()
|
||||
|
||||
if PACKAGES != "":
|
||||
LINK_FLAGS = "-linkpkg "+PACKAGES
|
||||
|
||||
header = [
|
||||
"""
|
||||
########################################################
|
||||
# This file was auto-generated. #
|
||||
# This file will be overwritten. Don't edit this file! #
|
||||
# Changes should be done in the build.ninja file. #
|
||||
########################################################
|
||||
|
||||
""",
|
||||
|
||||
"PACKAGES=%s"%(PACKAGES),
|
||||
"THREAD=%s"%(THREAD),
|
||||
"SYNTAX=%s"%(SYNTAX),
|
||||
"OCAMLC_FLAGS=%s"%(OCAMLC_FLAGS),
|
||||
"LINK_FLAGS=%s"%(LINK_FLAGS),
|
||||
"GENERATED_NINJA=%s"%(GENERATED_NINJA),
|
||||
]
|
||||
|
||||
header += """
|
||||
rule ocamlc
|
||||
command = ocamlfind ocamlc -c $OCAMLC_FLAGS $THREAD $PACKAGES $SYNTAX -o $out $in
|
||||
description = Compiling $out (bytecode)
|
||||
|
||||
rule ocamlopt
|
||||
command = ocamlfind ocamlopt -c $OCAMLC_FLAGS $THREAD $PACKAGES $SYNTAX -o $o $in
|
||||
description = Compiling $out (native)
|
||||
|
||||
rule ocamlc_link
|
||||
command = ocamlfind ocamlc $OCAMLC_FLAGS $THREAD $LINK_FLAGS $PACKAGES $SYNTAX -o $out $in
|
||||
description = Compiling $out (bytecode)
|
||||
|
||||
rule ocamlopt_link
|
||||
command = ocamlfind ocamlopt $OCAMLC_FLAGS $THREAD $LINK_FLAGS $PACKAGES $SYNTAX -o $out $in
|
||||
description = Compiling $out (native)
|
||||
|
||||
""".splitlines()
|
||||
|
||||
# Get the list of .ml files
|
||||
all_files = os.listdir(os.getcwd())
|
||||
files = [ os.path.splitext(i)[0] for i in all_files if i.endswith('.ml') ]
|
||||
while "myocamlbuild" in files:
|
||||
files.remove("myocamlbuild")
|
||||
ml_files = ' '.join( [ '%s.ml'%i for i in files ] )
|
||||
|
||||
# Dependencies
|
||||
result = subprocess.Popen(
|
||||
("ocamlfind ocamldep {0} {1} {2}".format(PACKAGES,SYNTAX,ml_files)).split()
|
||||
,stdout=subprocess.PIPE).communicate()[0]
|
||||
result = result.replace('\\\n',' ')
|
||||
dependencies = {}
|
||||
for line in result.splitlines():
|
||||
key, value = line.split(':')
|
||||
dependencies[key.strip()] = value.strip()
|
||||
|
||||
result = header
|
||||
template = """
|
||||
build {0}.cmi: ocamlc {0}.mli | $GENERATED_NINJA
|
||||
build {0}.cmo: ocamlc {0}.ml | $GENERATED_NINJA {1}
|
||||
build {0}.cmx {0}.o: ocamlopt {0}.ml | $GENERATED_NINJA {2}
|
||||
o = {0}.o
|
||||
"""
|
||||
|
||||
template_root_byte = """
|
||||
build {2}.byte: ocamlc_link {1} {0}
|
||||
"""
|
||||
|
||||
template_root_native = """
|
||||
build {2}: ocamlopt_link {1} {0}
|
||||
"""
|
||||
|
||||
# Find roots
|
||||
dep = {}
|
||||
for f in dependencies:
|
||||
dep[f] = [ i.strip() for i in dependencies[f].split() ]
|
||||
|
||||
roots = {}
|
||||
for f in dependencies:
|
||||
Found = False
|
||||
for g,l in dep.iteritems():
|
||||
if f in l:
|
||||
Found = True
|
||||
if not Found:
|
||||
roots[f] = []
|
||||
|
||||
def get_deps(l):
|
||||
result = []
|
||||
for i in l:
|
||||
if i in dep:
|
||||
result += get_deps(dep[i])
|
||||
result += l
|
||||
newresult = []
|
||||
for r in result:
|
||||
if r not in newresult:
|
||||
newresult.append(r)
|
||||
return newresult
|
||||
|
||||
for r in roots:
|
||||
roots[r] = [ i for i in get_deps(dep[r]) if not i.endswith(".cmi") ]
|
||||
|
||||
# Write the $GENERATED_NINJA file
|
||||
result += [ template.format(basename,
|
||||
dependencies["%s.cmo"%basename],
|
||||
dependencies["%s.cmx"%basename]
|
||||
) for basename in files ]
|
||||
result += [ template_root_byte.format(basename,
|
||||
' '.join(roots[basename]),
|
||||
os.path.splitext(basename)[0]
|
||||
) for basename in roots if basename.endswith('.cmo')]
|
||||
result += [ template_root_native.format(basename,
|
||||
' '.join(roots[basename]),
|
||||
os.path.splitext(basename)[0]
|
||||
) for basename in roots if basename.endswith('.cmx')]
|
||||
|
||||
output = '\n'.join(result)
|
||||
try:
|
||||
with open(GENERATED_NINJA,'r') as f:
|
||||
inp = f.read()
|
||||
except IOError:
|
||||
inp = ""
|
||||
|
||||
if inp != output:
|
||||
with open(GENERATED_NINJA,'w') as f:
|
||||
f.write(output)
|
||||
|
||||
def create_build_ninja ():
|
||||
with open('build.ninja','w') as f:
|
||||
f.write("""
|
||||
MAIN=
|
||||
# Main program to build
|
||||
|
||||
PACKAGES=
|
||||
# Required opam packages, for example:
|
||||
# PACKAGES=-package core
|
||||
|
||||
THREAD=
|
||||
# If you need threding support, use:
|
||||
# THREAD=-thread
|
||||
|
||||
SYNTAX=
|
||||
# If you need pre-processing, use:
|
||||
# SYNTAX=-syntax camlp4o
|
||||
|
||||
OCAMLC_FLAGS=
|
||||
# Flags to give to ocamlc, for example:
|
||||
# OCAMLC_FLAGS=-g -warn-error A
|
||||
|
||||
LINK_FLAGS=
|
||||
# Flags to give to the linker, for example:
|
||||
# LINK_FLAGS=-cclib '-Wl,-rpath=../lib,--enable-new-dtags'
|
||||
|
||||
GENERATED_NINJA=generated.ninja
|
||||
# Name of the auto-generated ninja file
|
||||
|
||||
rule create_generated
|
||||
command = python2 ./ninja_ocaml.py
|
||||
description = Finding dependencies between modules
|
||||
|
||||
rule run_ninja
|
||||
command = ninja -f $in $target
|
||||
description = Compiling OCaml executables
|
||||
pool = console
|
||||
|
||||
rule run_clean
|
||||
command = ninja -f $GENERATED_NINJA -t clean ; rm $GENERATED_NINJA
|
||||
pool = console
|
||||
description = Cleaning directory
|
||||
|
||||
rule ocamlc
|
||||
command = ocamlfind ocamlc -c $OCAMLC_FLAGS $THREAD $PACKAGES $SYNTAX -o $out $in
|
||||
description = Compiling $in (bytecode)
|
||||
|
||||
rule ocamlopt
|
||||
command = ocamlfind ocamlopt -c $OCAMLC_FLAGS $THREAD $PACKAGES $SYNTAX -o $out $in
|
||||
description = Compiling $in (native)
|
||||
|
||||
rule ocamlc_link
|
||||
command = ocamlfind ocamlc $OCAMLC_FLAGS $THREAD $LINK_FLAGS $PACKAGES $SYNTAX -o $out $in
|
||||
description = Compiling $out (bytecode)
|
||||
|
||||
rule ocamlopt_link
|
||||
command = ocamlfind ocamlopt $OCAMLC_FLAGS $THREAD $LINK_FLAGS $PACKAGES $SYNTAX -o $out $in
|
||||
description = Compiling $out (native)
|
||||
|
||||
|
||||
build clean: run_clean
|
||||
build always $GENERATED_NINJA: create_generated
|
||||
|
||||
build $MAIN: run_ninja $GENERATED_NINJA
|
||||
target = $MAIN
|
||||
|
||||
build all: run_ninja $GENERATED_NINJA
|
||||
target =
|
||||
|
||||
default $MAIN
|
||||
|
||||
""")
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
for h in "help -h -help --help ?".split():
|
||||
if h in sys.argv:
|
||||
_help_ ()
|
||||
return
|
||||
|
||||
if "build.ninja" in os.listdir(os.getcwd()):
|
||||
create_generated_ninja ()
|
||||
else:
|
||||
create_build_ninja ()
|
||||
print """
|
||||
==========================================================
|
||||
A default build.ninja file was created.
|
||||
Now, edit build.ninja and compile your project using:
|
||||
|
||||
ninja
|
||||
|
||||
==========================================================
|
||||
"""
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
@ -1,16 +1,60 @@
|
||||
open Core
|
||||
let update_command_line () =
|
||||
let last = (Array.length Sys.argv) - 2 in
|
||||
Sys.argv.(0) <- Sys.argv.(0) ^ "_" ^ Sys.argv.(1);
|
||||
for i=1 to last do
|
||||
Sys.argv.(i) <- Sys.argv.(i+1)
|
||||
done;
|
||||
Sys.argv.(last+1) <- ""
|
||||
|
||||
|
||||
let command =
|
||||
Command.group ~summary:"QMC=Chem command" [
|
||||
"debug" , Qmcchem_debug.command ;
|
||||
"edit" , Qmcchem_edit.command ;
|
||||
"info" , Qmcchem_info.command ;
|
||||
"md5" , Qmcchem_md5.command ;
|
||||
"result", Qmcchem_result.command ;
|
||||
"run" , Qmcchem_run.command ;
|
||||
"stop" , Qmcchem_stop.command ;
|
||||
]
|
||||
let help () =
|
||||
Printf.printf "
|
||||
qmcchem - QMC=Chem command
|
||||
|
||||
Usage:
|
||||
|
||||
qmcchem [-h] COMMAND
|
||||
|
||||
Arguments:
|
||||
|
||||
COMMAND QMC=Chem command to run :
|
||||
[run|edit|stop|result|md5|info|debug]
|
||||
|
||||
Options:
|
||||
|
||||
-h --help Prints the help message.
|
||||
|
||||
Description:
|
||||
|
||||
Driver for subcommands.
|
||||
|
||||
"
|
||||
|
||||
let () =
|
||||
Command.run command
|
||||
if Array.length Sys.argv < 2 then
|
||||
(help (); failwith "Inconsistent command line") ;
|
||||
|
||||
match String.trim Sys.argv.(1) with
|
||||
| "-h" | "--help" ->
|
||||
begin
|
||||
help () ;
|
||||
exit 0
|
||||
end
|
||||
| _ ->
|
||||
begin
|
||||
let command =
|
||||
Sys.argv.(1)
|
||||
in
|
||||
update_command_line ();
|
||||
|
||||
match command with
|
||||
| "debug" -> let open Qmcchem_debug in command ()
|
||||
| "edit" -> let open Qmcchem_edit in command ()
|
||||
| "info" -> let open Qmcchem_info in command ()
|
||||
| "md5" -> let open Qmcchem_md5 in command ()
|
||||
| "result" -> let open Qmcchem_result in command ()
|
||||
| "run" -> let open Qmcchem_run in command ()
|
||||
| "stop" -> let open Qmcchem_stop in command ()
|
||||
| _ -> (help () ; failwith "Inconsistent command line")
|
||||
end
|
||||
|
||||
|
@ -1,85 +1,98 @@
|
||||
open Core
|
||||
let global_replace x =
|
||||
x
|
||||
|> Str.global_replace (Str.regexp "Float.to_string") "string_of_float"
|
||||
|> Str.global_replace (Str.regexp "Float.of_string") "float_of_string"
|
||||
|> Str.global_replace (Str.regexp "Int.to_string") "string_of_int"
|
||||
|> Str.global_replace (Str.regexp "Int.of_string") "int_of_string"
|
||||
|> Str.global_replace (Str.regexp "String.\\(to\\|of\\)_string") ""
|
||||
|
||||
let input_data = "
|
||||
* Positive_float : float
|
||||
assert (x >= 0.) ;
|
||||
if not (x >= 0.) then
|
||||
raise (Invalid_argument (Printf.sprintf \"Positive_float : (x >= 0.) : x=%f\" x));
|
||||
|
||||
* Strictly_positive_float : float
|
||||
assert (x > 0.) ;
|
||||
if not (x > 0.) then
|
||||
raise (Invalid_argument (Printf.sprintf \"Strictly_positive_float : (x > 0.) : x=%f\" x));
|
||||
|
||||
* Negative_float : float
|
||||
assert (x <= 0.) ;
|
||||
if not (x <= 0.) then
|
||||
raise (Invalid_argument (Printf.sprintf \"Negative_float : (x <= 0.) : x=%f\" x));
|
||||
|
||||
* Strictly_negative_float : float
|
||||
assert (x < 0.) ;
|
||||
if not (x < 0.) then
|
||||
raise (Invalid_argument (Printf.sprintf \"Strictly_negative_float : (x < 0.) : x=%f\" x));
|
||||
|
||||
* Positive_int64 : int64
|
||||
if not (x >= 0L) then
|
||||
raise (Invalid_argument (Printf.sprintf \"Positive_int64 : (x >= 0L) : x=%s\" (Int64.to_string x)));
|
||||
|
||||
* Positive_int : int
|
||||
assert (x >= 0) ;
|
||||
if not (x >= 0) then
|
||||
raise (Invalid_argument (Printf.sprintf \"Positive_int : (x >= 0) : x=%d\" x));
|
||||
|
||||
* Strictly_positive_int : int
|
||||
assert (x > 0) ;
|
||||
if not (x > 0) then
|
||||
raise (Invalid_argument (Printf.sprintf \"Strictly_positive_int : (x > 0) : x=%d\" x));
|
||||
|
||||
* Negative_int : int
|
||||
if not (x <= 0) then
|
||||
raise (Invalid_argument (Printf.sprintf \"Negative_int : (x <= 0) : x=%d\" x));
|
||||
assert (x <= 0) ;
|
||||
|
||||
* Det_coef : float
|
||||
assert (x >= -1.) ;
|
||||
assert (x <= 1.) ;
|
||||
if (x < -1.) || (x > 1.) then
|
||||
raise (Invalid_argument (Printf.sprintf \"Det_coef : (-1. <= x <= 1.) : x=%f\" x));
|
||||
|
||||
* Normalized_float : float
|
||||
assert (x <= 1.) ;
|
||||
assert (x >= 0.) ;
|
||||
if (x < 0.) || (x > 1.) then
|
||||
raise (Invalid_argument (Printf.sprintf \"Normalized_float : (0. <= x <= 1.) : x=%f\" x));
|
||||
|
||||
* Strictly_negative_int : int
|
||||
assert (x < 0) ;
|
||||
if not (x < 0) then
|
||||
raise (Invalid_argument (Printf.sprintf \"Strictly_negative_int : (x < 0) : x=%d\" x));
|
||||
|
||||
* Non_empty_string : string
|
||||
assert (x <> \"\") ;
|
||||
if (x = \"\") then
|
||||
raise (Invalid_argument \"Non_empty_string\");
|
||||
|
||||
|
||||
* Det_number_max : int
|
||||
assert (x > 0) ;
|
||||
if (x > 100000000) then
|
||||
if (x > 100_000_000) then
|
||||
warning \"More than 100 million determinants\";
|
||||
"^
|
||||
(*
|
||||
"
|
||||
|
||||
* States_number : int
|
||||
assert (x > 0) ;
|
||||
if (x > 100) then
|
||||
warning \"More than 100 states\";
|
||||
if (Ezfio.has_determinants_n_states_diag ()) then
|
||||
assert (x <= (Ezfio.get_determinants_n_states_diag ()))
|
||||
else if (Ezfio.has_determinants_n_states ()) then
|
||||
assert (x <= (Ezfio.get_determinants_n_states ()));
|
||||
if (x > 1000) then
|
||||
warning \"More than 1000 states\";
|
||||
|
||||
* Bit_kind_size : int
|
||||
begin match x with
|
||||
| 8 | 16 | 32 | 64 -> ()
|
||||
| _ -> raise (Failure \"Bit_kind_size should be (8|16|32|64).\")
|
||||
| _ -> raise (Invalid_argument \"Bit_kind_size should be (8|16|32|64).\")
|
||||
end;
|
||||
|
||||
* Bit_kind : int
|
||||
begin match x with
|
||||
| 1 | 2 | 4 | 8 -> ()
|
||||
| _ -> raise (Failure \"Bit_kind should be (1|2|4|8).\")
|
||||
| _ -> raise (Invalid_argument \"Bit_kind should be (1|2|4|8).\")
|
||||
end;
|
||||
|
||||
* Bitmask_number : int
|
||||
assert (x > 0) ;
|
||||
"^
|
||||
*)
|
||||
"
|
||||
|
||||
* MO_coef : float
|
||||
|
||||
* MO_occ : float
|
||||
assert (x >= 0.);
|
||||
if x < 0. then 0. else
|
||||
if x > 2. then 2. else
|
||||
|
||||
* AO_coef : float
|
||||
|
||||
* AO_expo : float
|
||||
assert (x >= 0.) ;
|
||||
if (x < 0.) then
|
||||
raise (Invalid_argument (Printf.sprintf \"AO_expo : (x >= 0.) : x=%f\" x));
|
||||
|
||||
* AO_prim_number : int
|
||||
assert (x > 0) ;
|
||||
@ -102,6 +115,12 @@ let input_data = "
|
||||
|
||||
* MD5 : string
|
||||
assert ((String.length x) = 32);
|
||||
assert (
|
||||
let a =
|
||||
Array.init (String.length x) (fun i -> x.[i])
|
||||
in
|
||||
Array.fold_left (fun accu x -> accu && (x < 'g')) true a
|
||||
);
|
||||
|
||||
* Rst_string : string
|
||||
|
||||
@ -116,40 +135,36 @@ let input_data = "
|
||||
assert (x <> \"\") ;
|
||||
|
||||
"
|
||||
;;
|
||||
|
||||
|
||||
let input_ezfio = "
|
||||
* MO_number : int
|
||||
mo_basis_mo_tot_num
|
||||
1 : 10000
|
||||
More than 10000 MOs
|
||||
mo_basis_mo_num
|
||||
1 : 10_000
|
||||
More than 10_000 MOs
|
||||
|
||||
* AO_number : int
|
||||
ao_basis_ao_num
|
||||
1 : 10000
|
||||
More than 10000 AOs
|
||||
1 : 10_000
|
||||
More than 10_000 AOs
|
||||
|
||||
* Nucl_number : int
|
||||
nuclei_nucl_num
|
||||
1 : 10000
|
||||
More than 10000 nuclei
|
||||
1 : 10_000
|
||||
More than 10_000 nuclei
|
||||
|
||||
"^
|
||||
(*
|
||||
"
|
||||
* N_int_number : int
|
||||
determinants_n_int
|
||||
spindeterminants_n_int
|
||||
1 : 30
|
||||
N_int > 30
|
||||
|
||||
* Det_number : int
|
||||
determinants_n_det
|
||||
1 : 100000000
|
||||
spindeterminants_n_det
|
||||
1 : 100_000_000
|
||||
More than 100 million determinants
|
||||
|
||||
"
|
||||
*)
|
||||
""
|
||||
;;
|
||||
|
||||
|
||||
let untouched = "
|
||||
"
|
||||
@ -168,33 +183,37 @@ end = struct
|
||||
end
|
||||
|
||||
"
|
||||
;;
|
||||
|
||||
|
||||
|
||||
let parse_input input=
|
||||
print_string "open Sexplib.Std\nlet warning = print_string\n" ;
|
||||
let rec parse result = function
|
||||
| [] -> result
|
||||
| ( "" , "" )::tail -> parse result tail
|
||||
| ( t , text )::tail ->
|
||||
let name,typ,params,params_val =
|
||||
match String.split ~on:':' t with
|
||||
match String.split_on_char ':' t with
|
||||
| [name;typ] -> (name,typ,"","")
|
||||
| name::typ::params::params_val -> (name,typ,params,
|
||||
(String.concat params_val ~sep:":") )
|
||||
(String.concat ":" params_val) )
|
||||
| _ -> assert false
|
||||
in
|
||||
let typ = String.strip typ
|
||||
and name = String.strip name in
|
||||
let typ_cap = String.capitalize typ in
|
||||
let typ = String_ext.strip typ
|
||||
and name = String_ext.strip name in
|
||||
let typ_cap = String.capitalize_ascii typ in
|
||||
let newstring = Printf.sprintf template name typ typ typ params_val typ typ
|
||||
typ typ params ( String.strip text ) typ_cap
|
||||
typ typ params ( String_ext.strip text ) typ_cap
|
||||
in
|
||||
List.rev (parse (newstring::result) tail )
|
||||
in
|
||||
String.split ~on:'*' input
|
||||
|> List.map ~f:(String.lsplit2_exn ~on:'\n')
|
||||
String_ext.split ~on:'*' input
|
||||
|> List.map (String_ext.lsplit2_exn ~on:'\n')
|
||||
|> parse []
|
||||
|> String.concat
|
||||
;;
|
||||
|> String.concat ""
|
||||
|> global_replace
|
||||
|> print_string
|
||||
|
||||
|
||||
|
||||
let ezfio_template = format_of_string "
|
||||
@ -223,7 +242,9 @@ end = struct
|
||||
begin
|
||||
match max with
|
||||
| %s -> ()
|
||||
| i -> assert ( x <= i )
|
||||
| i ->
|
||||
if ( x > i ) then
|
||||
raise (Invalid_argument (Printf.sprintf \"%s: %%s\" (%s.to_string x) ))
|
||||
end ;
|
||||
x
|
||||
end
|
||||
@ -234,102 +255,103 @@ end
|
||||
let parse_input_ezfio input=
|
||||
let parse s =
|
||||
match (
|
||||
String.split s ~on:'\n'
|
||||
|> List.filter ~f:(fun x -> (String.strip x) <> "")
|
||||
String_ext.split s ~on:'\n'
|
||||
|> List.filter (fun x -> (String_ext.strip x) <> "")
|
||||
) with
|
||||
| [] -> ""
|
||||
| a :: b :: c :: d :: [] ->
|
||||
begin
|
||||
let (name,typ) = String.lsplit2_exn ~on:':' a
|
||||
let (name,typ) = String_ext.lsplit2_exn ~on:':' a
|
||||
and ezfio_func = b
|
||||
and (min, max) = String.lsplit2_exn ~on:':' c
|
||||
and (min, max) = String_ext.lsplit2_exn ~on:':' c
|
||||
and msg = d
|
||||
in
|
||||
let (name, typ, ezfio_func, min, max, msg) =
|
||||
match (List.map [ name ; typ ; ezfio_func ; min ; max ; msg ] ~f:String.strip) with
|
||||
match List.map String_ext.strip [ name ; typ ; ezfio_func ; min ; max ; msg ] with
|
||||
| [ name ; typ ; ezfio_func ; min ; max ; msg ] -> (name, typ, ezfio_func, min, max, msg)
|
||||
| _ -> assert false
|
||||
in
|
||||
Printf.sprintf ezfio_template
|
||||
name typ typ typ typ typ typ typ typ (String.capitalize typ)
|
||||
ezfio_func ezfio_func max min typ typ max msg min
|
||||
name typ typ typ typ typ typ typ typ (String.capitalize_ascii typ)
|
||||
ezfio_func ezfio_func max min typ typ max msg min name (String.capitalize_ascii typ)
|
||||
end
|
||||
| _ -> failwith "Error in input_ezfio"
|
||||
in
|
||||
String.split ~on:'*' input
|
||||
|> List.map ~f:parse
|
||||
|> String.concat
|
||||
String_ext.split ~on:'*' input
|
||||
|> List.map parse
|
||||
|> String.concat ""
|
||||
|> global_replace
|
||||
|> print_string
|
||||
|
||||
|
||||
|
||||
(** EZFIO *)
|
||||
let input_lines filename =
|
||||
let ic = open_in filename in
|
||||
let result = String_ext.input_lines ic in
|
||||
close_in ic;
|
||||
result
|
||||
|
||||
|
||||
let create_ezfio_handler () =
|
||||
let lines =
|
||||
In_channel.with_file "ezfio.ml" ~f:In_channel.input_lines
|
||||
|> List.filteri ~f:(fun i _ -> i > 470)
|
||||
input_lines "ezfio.ml"
|
||||
|> List.mapi (fun i l -> if i > 474 then Some l else None)
|
||||
|> List.filter (fun x -> x <> None)
|
||||
|> List.map (fun x ->
|
||||
match x with
|
||||
| Some x -> x
|
||||
| None -> assert false)
|
||||
in
|
||||
let functions =
|
||||
List.map lines ~f:(fun x ->
|
||||
match String.split x ~on:' ' with
|
||||
List.map (fun x ->
|
||||
match String.split_on_char ' ' x with
|
||||
| _ :: x :: "()" :: "=" :: f :: dir :: item :: _-> (x, f, dir, item)
|
||||
| _ :: x :: "=" :: f :: dir :: item :: _-> (x, f, dir, item)
|
||||
| _ -> ("","","","")
|
||||
)
|
||||
) lines
|
||||
in
|
||||
let has_functions =
|
||||
List.filter functions ~f:(fun (x,_,_,_) -> String.is_prefix ~prefix:"has_" x)
|
||||
List.filter (fun (x,_,_,_) -> String.sub x 0 4 = "has_") functions
|
||||
and get_functions =
|
||||
List.filter functions ~f:(fun (x,_,_,_) -> String.is_prefix ~prefix:"get_" x)
|
||||
List.filter (fun (x,_,_,_) -> String.sub x 0 4 = "get_") functions
|
||||
in
|
||||
let chop s =
|
||||
match (Str.split_delim (Str.regexp ";;") s) with
|
||||
| x :: _ -> x
|
||||
| _ -> assert false
|
||||
in
|
||||
|
||||
let result =
|
||||
[ "let decode_ezfio_message msg =
|
||||
match msg with " ] @
|
||||
(
|
||||
List.map get_functions ~f:(fun (x,f,d,i) ->
|
||||
let i =
|
||||
match (String.chop_suffix i ~suffix:";;") with
|
||||
| Some x -> x
|
||||
| None -> i
|
||||
in
|
||||
if (String.is_suffix f ~suffix:"_array") then
|
||||
List.map (fun (x,f,d,i) ->
|
||||
let i = chop i in
|
||||
if (String.sub f ((String.length f)-6) 6 = "_array") then
|
||||
Printf.sprintf " | \"%s\" ->
|
||||
Ezfio.read_string_array %s %s
|
||||
|> Ezfio.flattened_ezfio
|
||||
|> Array.to_list
|
||||
|> String.concat ~sep:\" \"" x d i
|
||||
|> String.concat \" \"" x d i
|
||||
else
|
||||
Printf.sprintf " | \"%s\" -> Ezfio.read_string %s %s" x d i
|
||||
)
|
||||
) get_functions
|
||||
) @ (
|
||||
List.map has_functions ~f:(fun (x,_,_,_) ->
|
||||
List.map (fun (x,_,_,_) ->
|
||||
Printf.sprintf " | \"%s\" -> if (Ezfio.%s ()) then \"T\" else \"F\"" x x
|
||||
)
|
||||
) has_functions
|
||||
) @ [" | x -> failwith (x^\" : Unknown EZFIO function\")\n;;"]
|
||||
in
|
||||
String.concat result ~sep:"\n"
|
||||
String.concat "\n" result
|
||||
|> print_endline
|
||||
|
||||
(** Main *)
|
||||
|
||||
let () =
|
||||
let input =
|
||||
String.concat ~sep:"\n"
|
||||
[ "open Core\nlet warning = print_string\n\n" ;
|
||||
parse_input input_data ;
|
||||
parse_input_ezfio input_ezfio;
|
||||
create_ezfio_handler ();
|
||||
untouched ]
|
||||
|
||||
and old_input =
|
||||
let filename =
|
||||
"Qptypes.ml"
|
||||
in
|
||||
match Sys.file_exists filename with
|
||||
| `Yes -> In_channel.read_all "Qptypes.ml"
|
||||
| `No | `Unknown -> "empty"
|
||||
|
||||
in
|
||||
|
||||
if input <> old_input then
|
||||
Out_channel.write_all "Qptypes.ml" ~data:input
|
||||
print_endline untouched;
|
||||
create_ezfio_handler ()
|
||||
|
||||
|
||||
|
||||
|
@ -1,14 +1,15 @@
|
||||
#!/bin/bash
|
||||
# This script is supposed to run in $QMCCHEM_PATH
|
||||
|
||||
ninja -C ocaml clean
|
||||
make -C ocaml clean
|
||||
if [[ -d src/IRPF90_temp ]]
|
||||
then
|
||||
ninja -C src/IRPF90_temp -t clean
|
||||
make -C src/IRPF90_temp clean
|
||||
fi
|
||||
ninja -t clean
|
||||
|
||||
rm -f ocaml/qmcchem ocaml/.ls_md5 ocaml/generated.ninja
|
||||
make -C EZFIO clean
|
||||
|
||||
rm -f ocaml/qmcchem ocaml/.ls_md5
|
||||
rm -f EZFIO/Ocaml/ezfio.ml
|
||||
cd src
|
||||
rm -rf tags irpf90_entities irpf90.make IRPF90_temp IRPF90_man .ls_md5
|
||||
|
@ -19,8 +19,11 @@ then
|
||||
REF=$(cat ${LSMD5_FILE})
|
||||
fi
|
||||
|
||||
if [[ ${MD5} != ${REF} ]]
|
||||
if [[ ${MD5} == ${REF} ]]
|
||||
then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo ${MD5} > ${LSMD5_FILE}
|
||||
echo Running IRPF90
|
||||
|
||||
@ -30,7 +33,7 @@ then
|
||||
SRC="${SRC} ZMQ/f77_zmq_module.f90"
|
||||
OBJ="${OBJ} IRPF90_temp/ZMQ/f77_zmq_module.o"
|
||||
INCLUDES="${INCLUDES} -I AO -I SAMPLING -I TOOLS -I JASTROW -I MAIN -I PROPERTIES -I ZMQ"
|
||||
IRPF90_FLAGS="${IRPF90_FLAGS} --ninja"
|
||||
IRPF90_FLAGS="${IRPF90_FLAGS}"
|
||||
|
||||
# Check IRPF90 version
|
||||
if [[ $( ${IRPF90} -v | python2 -c "import sys ; print float(sys.stdin.read().rsplit('.',1)[0]) >= 1.6") == False ]]
|
||||
@ -42,8 +45,5 @@ then
|
||||
export IRPF90 IRPF90_FLAGS INCLUDES LIB SRC OBJ
|
||||
|
||||
exec ${IRPF90} ${IRPF90_FLAGS} ${INCLUDES} || exit -1
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -8,4 +8,4 @@ fi
|
||||
|
||||
cd ${QMCCHEM_PATH}/ocaml || exit -1
|
||||
|
||||
exec ninja -f generated.ninja ${@} || exit -1
|
||||
exec make
|
||||
|
@ -1,31 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ -z ${QMCCHEM_PATH} ]]
|
||||
then
|
||||
echo "Error: qmcchemrc not loaded"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
cd ${QMCCHEM_PATH}/ocaml || exit -1
|
||||
|
||||
cp ${QMCCHEM_PATH}/EZFIO/Ocaml/ezfio.ml . || exit -1
|
||||
|
||||
LSMD5_FILE=${QMCCHEM_PATH}/ocaml/.ls_md5
|
||||
FILES="*.ml *.mli"
|
||||
MD5=$(ls -ltr --full-time ${FILES} 2>/dev/null | md5sum | cut -d ' ' -f 1)
|
||||
|
||||
REF=0
|
||||
|
||||
if [[ -f ${LSMD5_FILE} ]]
|
||||
then
|
||||
REF=$(cat ${LSMD5_FILE})
|
||||
fi
|
||||
|
||||
if [[ ${MD5} != ${REF} ]]
|
||||
then
|
||||
echo ${MD5} > ${LSMD5_FILE}
|
||||
echo Finding dependencies in OCaml files
|
||||
python2 ./ninja_ocaml.py || exit -1
|
||||
fi
|
||||
|
||||
|
@ -6,6 +6,25 @@ then
|
||||
exit -1
|
||||
fi
|
||||
|
||||
cd ${QMCCHEM_PATH}/src/IRPF90_temp || exit -1
|
||||
|
||||
exec ninja ${@}
|
||||
cd ${QMCCHEM_PATH}/src || exit -1
|
||||
|
||||
|
||||
source ${QMCCHEM_PATH}/make.config
|
||||
|
||||
LIB="${LIB} ${QMCCHEM_PATH}/lib/libezfio_irp.a ${QMCCHEM_PATH}/lib/libf77zmq.a ${QMCCHEM_PATH}/lib/libzmq.a -lstdc++ -lrt -lz"
|
||||
SRC="${SRC} ZMQ/f77_zmq_module.f90"
|
||||
OBJ="${OBJ} IRPF90_temp/ZMQ/f77_zmq_module.o"
|
||||
INCLUDES="${INCLUDES} -I AO -I SAMPLING -I TOOLS -I JASTROW -I MAIN -I PROPERTIES -I ZMQ"
|
||||
IRPF90_FLAGS="${IRPF90_FLAGS} ${INCLUDES}"
|
||||
|
||||
# Check IRPF90 version
|
||||
if [[ $( ${IRPF90} -v | python2 -c "import sys ; print float(sys.stdin.read().rsplit('.',1)[0]) >= 1.6") == False ]]
|
||||
then
|
||||
echo "IRPF90 version >= 1.6 required"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
export IRPF90 IRPF90_FLAGS INCLUDES LIB SRC OBJ
|
||||
|
||||
exec make ${@}
|
||||
|
1
src/.gitignore
vendored
1
src/.gitignore
vendored
@ -4,5 +4,4 @@ irpf90.make
|
||||
irpf90_entities
|
||||
tags
|
||||
.ls_md5
|
||||
Makefile
|
||||
properties.pyc
|
||||
|
6
src/Makefile
Normal file
6
src/Makefile
Normal file
@ -0,0 +1,6 @@
|
||||
IRPF90+= $(IRPF90_FLAGS)
|
||||
include irpf90.make
|
||||
export
|
||||
|
||||
irpf90.make: $(filter-out IRPF90_temp/%, $(wildcard */*.irp.f)) $(wildcard *.irp.f) $(wildcard *.inc.f) Makefile
|
||||
$(IRPF90)
|
@ -52,7 +52,7 @@ data = [ \
|
||||
]
|
||||
|
||||
data_no_set = [\
|
||||
("mo_basis_mo_tot_num" , "integer" , ""),
|
||||
("mo_basis_mo_num" , "integer" , ""),
|
||||
("pseudo_ao_pseudo_grid" , "double precision" , "(ao_num,pseudo_lmax+pseudo_lmax+1,pseudo_lmax-0+1,nucl_num,pseudo_grid_size)"),
|
||||
("pseudo_mo_pseudo_grid" , "double precision" , "(ao_num,pseudo_lmax+pseudo_lmax+1,pseudo_lmax-0+1,nucl_num,pseudo_grid_size)"),
|
||||
("pseudo_pseudo_dz_k" , "double precision" , "(nucl_num,pseudo_klocmax)"),
|
||||
|
@ -410,7 +410,7 @@ BEGIN_PROVIDER [ integer, mo_tot_num ]
|
||||
END_DOC
|
||||
|
||||
mo_tot_num = -1
|
||||
call get_mo_basis_mo_tot_num(mo_tot_num)
|
||||
call get_mo_basis_mo_num(mo_tot_num)
|
||||
if (mo_tot_num <= 0) then
|
||||
call abrt(irp_here,'Total number of MOs can''t be <0')
|
||||
endif
|
||||
|
Loading…
Reference in New Issue
Block a user