Skip to content

Commit 34b37de

Browse files
committed
moved bash tip to lammps tips
1 parent e878fbf commit 34b37de

File tree

2 files changed

+74
-62
lines changed

2 files changed

+74
-62
lines changed

docs/source/lammps.rst

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,71 @@ chmod and launch it using:
7575
7676
chmod +x ./myfile.sh
7777
oarsub -S ./myfile.sh
78+
79+
Launch multiple jobs using bash
80+
_______________________________
81+
82+
Assuming that one has the job submission script named *sub.sh* with name *lmp-myvariable-0*,
83+
that launch a lammps input script named *input.lmp* by passing a variable
84+
named *myvariable* into it. Additionally, here the job ID is used as an input for the random seed, allowing for example different initial configurations:
85+
86+
.. code:: bash
87+
88+
#!/bin/bash
89+
#OAR -n lmp-myvariable-0
90+
#OAR -l /nodes=1/cpu=1/core=4,walltime=48:00:00
91+
#OAR --stdout log-water.out
92+
#OAR --stderr log-water.err
93+
#OAR --project tamtam
94+
95+
# Path to the LAMMPS MPI executable
96+
lmp=/path/lmp_mpi
97+
98+
myvariable=0
99+
100+
# Run LAMMPS using MPI, with 4 processes, using the input from 'input.lmp'
101+
mpirun -np 4 ${lmp} -in input.lmp -var nb2 ${myvariable} -var seedin $OAR_JOBID
102+
103+
If one wants to launch the current job, one simply have to type:
104+
105+
.. code:: bash
106+
107+
chmod +x sub.sh
108+
oarsub -S ./sub.sh
109+
110+
and a single job with name *lmp-myvariable-0* will be send.
111+
To launch multiple simulations with different values of *myvariable*,
112+
say 0, 1, and 2, one can create a second bash script, named *multi-sub.sh*,
113+
and containing:
114+
115+
.. code:: bash
116+
117+
#!/bin/bash
118+
set -e
119+
120+
for myvariable in 0 1 2
121+
do
122+
# deal with OAR -n
123+
newline='#OAR -n lmp-myvariable-'$myvariable
124+
oldline=$(cat sub.sh | grep '#OAR -n lmp-myvariable-')
125+
sed -i '/'"$oldline"'/c\'"$newline" sub.sh
126+
# deal with myvariable
127+
newline='myvariable='$myvariable
128+
oldline=$(cat sub.sh | grep 'myvariable =')
129+
sed -i '/'"$oldline"'/c\'"$newline" sub.sh
130+
chmod +x sub.sh
131+
oarsub -S ./sub.sh
132+
done
133+
134+
The *newline* command creates a new line that will replace the line
135+
containing *myvariable* in the script sub.sh
136+
The *oldline=* command finds the current line in sub.sh that contains 'myvariable =',
137+
storing it in the variable oldline. This assumes there is exactly one such line,
138+
otherwise the behavior may be unexpected. Then, sed is used to replace the old
139+
line with the new line (newline) in *sub.sh*.
140+
141+
Then, simply run *multi-sub.sh* by typing:
142+
143+
.. code:: bash
144+
145+
bash multi-sub.sh

docs/source/oar.rst

Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -45,70 +45,14 @@ Launch Multiple Jobs
4545

4646
Here, tips to efficiently launch multiple jobs are provided.
4747

48-
Batch Job Submission
49-
____________________
50-
51-
Assuming that one has the job submission script named *sub.sh* with name *lmp-myvariable-0*,
52-
that launch a lammps input script named *input.lmp* by passing a variable
53-
named *myvariable* into it. Additionally, here the job ID is used as an input for the random seed, allowing for example different initial configurations:
48+
.. SG: this will be completed when Romain send me an example.
5449
5550
.. code:: bash
5651
5752
#!/bin/bash
58-
#OAR -n lmp-myvariable-0
59-
#OAR -l /nodes=1/cpu=1/core=4,walltime=48:00:00
60-
#OAR --stdout log-water.out
61-
#OAR --stderr log-water.err
62-
#OAR --project tamtam
63-
64-
# Path to the LAMMPS MPI executable
65-
lmp=/path/lmp_mpi
66-
67-
myvariable=0
68-
69-
# Run LAMMPS using MPI, with 4 processes, using the input from 'input.lmp'
70-
mpirun -np 4 ${lmp} -in input.lmp -var nb2 ${myvariable} -var seedin $OAR_JOBID
71-
72-
If one wants to launch the current job, one simply have to type:
73-
74-
.. code:: bash
75-
76-
chmod +x sub.sh
77-
oarsub -S ./sub.sh
78-
79-
and a single job with name *lmp-myvariable-0* will be send.
80-
To launch multiple simulations with different values of *myvariable*,
81-
say 0, 1, and 2, one can create a second bash script, named *multi-sub.sh*,
82-
and containing:
83-
84-
.. code:: bash
85-
86-
#!/bin/bash
87-
set -e
88-
89-
for myvariable in 0 1 2
90-
do
91-
# deal with OAR -n
92-
newline='#OAR -n lmp-myvariable-'$myvariable
93-
oldline=$(cat sub.sh | grep '#OAR -n lmp-myvariable-')
94-
sed -i '/'"$oldline"'/c\'"$newline" sub.sh
95-
# deal with myvariable
96-
newline='myvariable='$myvariable
97-
oldline=$(cat sub.sh | grep 'myvariable =')
98-
sed -i '/'"$oldline"'/c\'"$newline" sub.sh
99-
chmod +x sub.sh
100-
oarsub -S ./sub.sh
101-
done
102-
103-
The *newline* command creates a new line that will replace the line
104-
containing *myvariable* in the script sub.sh
105-
The *oldline=* command finds the current line in sub.sh that contains 'myvariable =',
106-
storing it in the variable oldline. This assumes there is exactly one such line,
107-
otherwise the behavior may be unexpected. Then, sed is used to replace the old
108-
line with the new line (newline) in *sub.sh*.
109-
110-
Then, simply run *multi-sub.sh* by typing:
111-
112-
.. code:: bash
53+
...
54+
#OAR --array 50
11355
114-
bash multi-sub.sh
56+
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
57+
temperatures=(0.25 0.5 1 .... )
58+
T=${temperatures[${id}]}

0 commit comments

Comments
 (0)