Skip to content

Commit

Permalink
Merge pull request #12 from psm-compute/launch-multiple
Browse files Browse the repository at this point in the history
started collecting multiple job handeling
  • Loading branch information
simongravelle authored Sep 24, 2024
2 parents 9ee4664 + f03f4b7 commit d0453cd
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 5 deletions.
82 changes: 77 additions & 5 deletions docs/source/lammps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Then, from the ``src/`` folder, type:
Run LAMMPS
----------

Create a bash (``.sh``) file with the following content:
Create a bash file named *sub.sh* with the following content:

.. code-block:: bash
Expand All @@ -64,14 +64,86 @@ Create a bash (``.sh``) file with the following content:
#OAR --stderr log.err
#OAR --project tamtam
mpirun -np 4 /PATH-TO-LAMMPS/lmp_mpi -in input.lmp
# Path to the LAMMPS executable
lmp=/path/lmp_mpi
where ``input.lmp`` is your LAMMPS input file, and there the project was assumed
mpirun -np 4 ${lmp} -in input.lmp
where ``input.lmp`` is your LAMMPS input file, and where the project was assumed
to be `tamtam` (to adapt to your case). Here, 4 CPU cores are requested,
as well as a total duration of 12 hours. Then, make the file file executable with
chmod and launch it using:

.. code-block:: bash
chmod +x ./myfile.sh
oarsub -S ./myfile.sh
chmod +x ./sub.sh
oarsub -S ./sub.sh
Launch multiple jobs using bash
_______________________________

Assuming that one has the job submission script named *sub.sh* with name *lmp-myvariable-0*,
that launch a lammps input script named *input.lmp* by passing a variable
named *myvariable* into it. Additionally, here the job ID is used as an
input for the random seed, allowing for example different initial configurations:

.. code:: bash
#!/bin/bash
#OAR -n lmp-myvariable-0
#OAR -l /nodes=1/cpu=1/core=4,walltime=12:00:00
#OAR --stdout log.out
#OAR --stderr log.err
#OAR --project tamtam
# Path to the LAMMPS executable
lmp=/path/lmp_mpi
myvariable=0
# Run LAMMPS using MPI, with 4 processes, using the input from 'input.lmp'
mpirun -np 4 ${lmp} -in input.lmp -var nb2 ${myvariable} -var seedin $OAR_JOBID
If one wants to launch the current job, one simply have to type:

.. code:: bash
chmod +x sub.sh
oarsub -S ./sub.sh
and a single job with name *lmp-myvariable-0* will be send.
To launch multiple simulations with different values of *myvariable*,
say 0, 1, and 2, one can create a second bash script, named *multi-sub.sh*,
and containing:

.. code:: bash
#!/bin/bash
set -e
for myvariable in 0 1 2
do
# deal with OAR -n
newline='#OAR -n lmp-myvariable-'$myvariable
oldline=$(cat sub.sh | grep '#OAR -n lmp-myvariable-')
sed -i '/'"$oldline"'/c\'"$newline" sub.sh
# deal with myvariable
newline='myvariable='$myvariable
oldline=$(cat sub.sh | grep 'myvariable =')
sed -i '/'"$oldline"'/c\'"$newline" sub.sh
chmod +x sub.sh
oarsub -S ./sub.sh
done
The *newline* command creates a new line that will replace the line
containing *myvariable* in the script sub.sh
The *oldline=* command finds the current line in sub.sh that contains 'myvariable =',
storing it in the variable oldline. This assumes there is exactly one such line,
otherwise the behavior may be unexpected. Then, sed is used to replace the old
line with the new line (newline) in *sub.sh*.

Then, simply run *multi-sub.sh* by typing:

.. code:: bash
bash multi-sub.sh
16 changes: 16 additions & 0 deletions docs/source/oar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,19 @@ You can cancel all your jobs at once by typing:
where username should be replaced by your ID.

Launch Multiple Jobs
--------------------

Here, tips to efficiently launch multiple jobs are provided.

.. SG: this will be completed when Romain send me an example.
.. code:: bash
#!/bin/bash
...
#OAR --array 50
id=`echo "$OAR_JOB_ID - $OAR_ARRAY_ID + 2" | bc -l` # <---- This id runs from 0 to 50, each job gets one, with which you can e.g. index a bash array
temperatures=(0.25 0.5 1 .... )
T=${temperatures[${id}]}

0 comments on commit d0453cd

Please sign in to comment.