Repository: HECBioSim/Longbow

Issue:
memory parameter only used in PBS
Either rename this to pbs-memory to denote that it is pbs only or add support in the other schedulers.

Discussion:

Patch:
diff --git a/longbow/schedulers/lsf.py b/longbow/schedulers/lsf.py
index ab20689..8992636 100644
--- a/longbow/schedulers/lsf.py
+++ b/longbow/schedulers/lsf.py
@@ -98,6 +98,10 @@ def prepare(job):
 
         jobfile.write("#BSUB -m " + job["lsf-cluster"] + "\n")
 
+    if job["memory"] is not "":
+
+        jobfile.write('#BSUB -R "rusage[mem=' + job["memory"] + 'G]"\n')
+
     # Account to charge (if supplied).
     if job["account"] is not "":
 
diff --git a/longbow/schedulers/pbs.py b/longbow/schedulers/pbs.py
index 1f490a5..dd5a1e1 100644
--- a/longbow/schedulers/pbs.py
+++ b/longbow/schedulers/pbs.py
@@ -131,16 +131,13 @@ def prepare(job):
     # Number of mpi processes per node.
     mpiprocs = cpn
 
-    # Memory size (used to select nodes with minimum memory).
-    memory = job["memory"]
-
     tmp = "select=" + nodes + ":ncpus=" + ncpus + ":mpiprocs=" + mpiprocs
 
     # If user has specified memory append the flag (not all machines support
     # this).
-    if memory is not "":
+    if job["memory"] is not "":
 
-        tmp = tmp + ":mem=" + memory + "gb"
+        tmp = tmp + ":mem=" + job["memory"] + "gb"
 
     # Write the resource requests
     jobfile.write("#PBS -l " + tmp + "\n")
diff --git a/longbow/schedulers/sge.py b/longbow/schedulers/sge.py
index a249375..c1acd0f 100644
--- a/longbow/schedulers/sge.py
+++ b/longbow/schedulers/sge.py
@@ -102,6 +102,10 @@ def prepare(job):
 
     jobfile.write("#$ -l h_rt=" + job["maxtime"] + ":00\n")
 
+    if job["memory"] is not "":
+
+        jobfile.write("#$ -l h_vmem=" + job["memory"] + "G\n")
+
     # Email user.
     if job["email-address"] is not "":
 
diff --git a/longbow/schedulers/slurm.py b/longbow/schedulers/slurm.py
index 22b8661..752e83a 100644
--- a/longbow/schedulers/slurm.py
+++ b/longbow/schedulers/slurm.py
@@ -100,6 +100,10 @@ def prepare(job):
             jobfile.write("#SBATCH " + job["accountflag"] + " " +
                           job["account"] + "\n")
 
+    if job["memory"] is not "":
+
+        jobfile.write("#SBATCH --mem=" + job["memory"] + "G" + "\n")
+
     # Generic resource (if supplied)
     if job["slurm-gres"] is not "":
 
diff --git a/longbow/schedulers/soge.py b/longbow/schedulers/soge.py
index a1d0223..9217a95 100644
--- a/longbow/schedulers/soge.py
+++ b/longbow/schedulers/soge.py
@@ -103,6 +103,10 @@ def prepare(job):
 
     jobfile.write("#$ -l h_rt=" + job["maxtime"] + ":00\n")
 
+    if job["memory"] is not "":
+
+        jobfile.write("#$ -l h_vmem=" + job["memory"] + "G\n")
+
     # Email user.
     if job["email-address"] is not "":
 


Test patch:
diff --git a/tests/standards/lsf_submitfiles/case9.txt b/tests/standards/lsf_submitfiles/case9.txt
new file mode 100644
index 0000000..60275d9
--- /dev/null
+++ b/tests/standards/lsf_submitfiles/case9.txt
@@ -0,0 +1,10 @@
+#!/bin/bash --login
+#BSUB -J testjob
+#BSUB -q debug
+#BSUB -R "rusage[mem=10G]"
+#BSUB -W 24:00
+#BSUB -n 24
+
+module load amber
+
+mpiexec.hydra pmemd.MPI -O -i e.in -c e.min -p e.top -o e.out
diff --git a/tests/standards/sge_submitfiles/case8.txt b/tests/standards/sge_submitfiles/case8.txt
new file mode 100644
index 0000000..f05a1be
--- /dev/null
+++ b/tests/standards/sge_submitfiles/case8.txt
@@ -0,0 +1,9 @@
+#!/bin/bash --login
+#$ -cwd -V
+#$ -N testjob
+#$ -q debug
+#$ -l h_rt=24:00:00
+#$ -l h_vmem=10G
+module load amber
+
+mpiexec pmemd.MPI -O -i e.in -c e.min -p e.top -o e.out
diff --git a/tests/standards/slurm_submitfiles/case8.txt b/tests/standards/slurm_submitfiles/case8.txt
new file mode 100644
index 0000000..bcef936
--- /dev/null
+++ b/tests/standards/slurm_submitfiles/case8.txt
@@ -0,0 +1,15 @@
+#!/bin/bash --login
+#SBATCH -J testjob
+#SBATCH -p debug
+#SBATCH --mem=10G
+#SBATCH --gres=gpu:1
+#SBATCH -n 24
+#SBATCH -N 1
+#SBATCH -t 24:00:00
+
+ls /dir
+cd /dir
+
+module load amber
+
+mpirun pmemd.MPI -O -i e.in -c e.min -p e.top -o e.out
diff --git a/tests/standards/soge_submitfiles/case8.txt b/tests/standards/soge_submitfiles/case8.txt
new file mode 100644
index 0000000..5166c90
--- /dev/null
+++ b/tests/standards/soge_submitfiles/case8.txt
@@ -0,0 +1,12 @@
+#!/bin/bash --login
+#$ -cwd -V
+#$ -N testjob
+#$ -q debug
+#$ -l h_rt=24:00:00
+#$ -l h_vmem=10G
+#$ -l nodes=1
+#$ -pe ib 12
+
+module load amber
+
+mpiexec pmemd.MPI -O -i e.in -c e.min -p e.top -o e.out
diff --git a/tests/unit/schedulers_lsf/test_lsf_prepare.py b/tests/unit/schedulers_lsf/test_lsf_prepare.py
index 3a4d462..e22c2b9 100644
--- a/tests/unit/schedulers_lsf/test_lsf_prepare.py
+++ b/tests/unit/schedulers_lsf/test_lsf_prepare.py
@@ -55,6 +55,7 @@ def test_prepare_case1():
         "localworkdir": "/tmp",
         "lsf-cluster": "",
         "maxtime": "24:00",
+        "memory": "",
         "modules": "amber",
         "queue": "debug",
         "replicates": "1",
@@ -89,6 +90,7 @@ def test_prepare_case2():
         "localworkdir": "/tmp",
         "lsf-cluster": "",
         "maxtime": "24:00",
+        "memory": "",
         "modules": "amber",
         "queue": "debug",
         "replicates": "5",
@@ -121,6 +123,7 @@ def test_prepare_case3():
         "localworkdir": "/tmp",
         "lsf-cluster": "cluster1",
         "maxtime": "24:00",
+        "memory": "",
         "modules": "amber",
         "queue": "debug",
         "replicates": "1",
@@ -154,6 +157,7 @@ def test_prepare_case4():
         "localworkdir": "/tmp",
         "lsf-cluster": "",
         "maxtime": "24:00",
+        "memory": "",
         "modules": "amber",
         "queue": "debug",
         "replicates": "1",
@@ -187,6 +191,7 @@ def test_prepare_case5():
         "localworkdir": "/tmp",
         "lsf-cluster": "",
         "maxtime": "24:00",
+        "memory": "",
         "modules": "amber",
         "queue": "debug",
         "replicates": "1",
@@ -220,6 +225,7 @@ def test_prepare_case6():
         "localworkdir": "/tmp",
         "lsf-cluster": "",
         "maxtime": "24:00",
+        "memory": "",
         "modules": "amber",
         "queue": "debug",
         "replicates": "1",
@@ -253,6 +259,7 @@ def test_prepare_case7():
         "localworkdir": "/tmp",
         "lsf-cluster": "",
         "maxtime": "24:00",
+        "memory": "",
         "modules": "amber",
         "queue": "debug",
         "replicates": "1",
@@ -286,6 +293,7 @@ def test_prepare_case8():
         "localworkdir": "/tmp",
         "lsf-cluster": "",
         "maxtime": "24:00",
+        "memory": "",
         "modules": "amber",
         "queue": "debug",
         "replicates": "1",
@@ -299,3 +307,37 @@ def test_prepare_case8():
         os.path.join(
             os.getcwd(),
             "tests/standards/lsf_submitfiles/case8.txt"), "rb").read()
+
+
+def test_prepare_case9():
+
+    """
+    Test handler parameters
+    """
+
+    job = {
+        "account": "",
+        "accountflag": "",
+        "cores": "24",
+        "executableargs": "pmemd.MPI -O -i e.in -c e.min -p e.top -o e.out",
+        "handler": "mpiexec.hydra",
+        "email-address": "",
+        "email-flags": "",
+        "jobname": "testjob",
+        "localworkdir": "/tmp",
+        "lsf-cluster": "",
+        "maxtime": "24:00",
+        "memory": "10",
+        "modules": "amber",
+        "queue": "debug",
+        "replicates": "1",
+        "scripts": "",
+        "upload-include": "file1, file2"
+    }
+
+    prepare(job)
+
+    assert open("/tmp/submit.lsf", "rb").read() == open(
+        os.path.join(
+            os.getcwd(),
+            "tests/standards/lsf_submitfiles/case9.txt"), "rb").read()
diff --git a/tests/unit/schedulers_sge/test_sge_prepare.py b/tests/unit/schedulers_sge/test_sge_prepare.py
index f08aac8..a462308 100644
--- a/tests/unit/schedulers_sge/test_sge_prepare.py
+++ b/tests/unit/schedulers_sge/test_sge_prepare.py
@@ -295,3 +295,40 @@ def test_prepare_case7():
         os.path.join(
             os.getcwd(),
             "tests/standards/sge_submitfiles/case7.txt"), "rb").read()
+
+
+def test_prepare_case8():
+
+    """
+    Test memory param
+    """
+
+    job = {
+        "account": "",
+        "accountflag": "",
+        "cluster": "",
+        "cores": "1",
+        "corespernode": "",
+        "executableargs": "pmemd.MPI -O -i e.in -c e.min -p e.top -o e.out",
+        "handler": "mpiexec",
+        "email-address": "",
+        "email-flags": "",
+        "jobname": "testjob",
+        "localworkdir": "/tmp",
+        "maxtime": "24:00",
+        "memory": "10",
+        "modules": "amber",
+        "queue": "debug",
+        "replicates": "1",
+        "scripts": "",
+        "sge-peflag": "mpi",
+        "sge-peoverride": "false",
+        "upload-include": "file1, file2"
+    }
+
+    prepare(job)
+
+    assert open("/tmp/submit.sge", "rb").read() == open(
+        os.path.join(
+            os.getcwd(),
+            "tests/standards/sge_submitfiles/case8.txt"), "rb").read()
diff --git a/tests/unit/schedulers_slurm/test_slurm_prepare.py b/tests/unit/schedulers_slurm/test_slurm_prepare.py
index 9219865..f40bebe 100644
--- a/tests/unit/schedulers_slurm/test_slurm_prepare.py
+++ b/tests/unit/schedulers_slurm/test_slurm_prepare.py
@@ -302,3 +302,41 @@ def test_prepare_case7():
         os.path.join(
             os.getcwd(),
             "tests/standards/slurm_submitfiles/case7.txt"), "rb").read()
+
+
+def test_prepare_case8():
+
+    """
+    Test gres parameters
+    """
+
+    job = {
+        "account": "",
+        "accountflag": "",
+        "cluster": "",
+        "cores": "24",
+        "corespernode": "24",
+        "executableargs": "pmemd.MPI -O -i e.in -c e.min -p e.top -o e.out",
+        "handler": "mpirun",
+        "email-address": "",
+        "email-flags": "",
+        "jobname": "testjob",
+        "localworkdir": "/tmp",
+        "maxtime": "24:00",
+        "memory": "10",
+        "modules": "amber",
+        "queue": "debug",
+        "replicates": "1",
+        "scripts": "ls /dir, cd /dir",
+        "slurm-gres": "gpu:1",
+        "sge-peflag": "mpi",
+        "sge-peoverride": "false",
+        "upload-include": "file1, file2"
+    }
+
+    prepare(job)
+
+    assert open("/tmp/submit.slurm", "rb").read() == open(
+        os.path.join(
+            os.getcwd(),
+            "tests/standards/slurm_submitfiles/case8.txt"), "rb").read()
diff --git a/tests/unit/schedulers_soge/test_soge_prepare.py b/tests/unit/schedulers_soge/test_soge_prepare.py
index e8666c8..dbf9615 100644
--- a/tests/unit/schedulers_soge/test_soge_prepare.py
+++ b/tests/unit/schedulers_soge/test_soge_prepare.py
@@ -295,3 +295,40 @@ def test_prepare_case7():
         os.path.join(
             os.getcwd(),
             "tests/standards/soge_submitfiles/case7.txt"), "rb").read()
+
+
+def test_prepare_case8():
+
+    """
+    Test under subscription
+    """
+
+    job = {
+        "account": "",
+        "accountflag": "",
+        "cluster": "",
+        "cores": "12",
+        "corespernode": "24",
+        "executableargs": "pmemd.MPI -O -i e.in -c e.min -p e.top -o e.out",
+        "handler": "mpiexec",
+        "email-address": "",
+        "email-flags": "",
+        "jobname": "testjob",
+        "localworkdir": "/tmp",
+        "maxtime": "24:00",
+        "memory": "10",
+        "modules": "amber",
+        "queue": "debug",
+        "replicates": "1",
+        "scripts": "",
+        "sge-peflag": "mpi",
+        "sge-peoverride": "false",
+        "upload-include": "file1, file2"
+    }
+
+    prepare(job)
+
+    assert open("/tmp/submit.soge", "rb").read() == open(
+        os.path.join(
+            os.getcwd(),
+            "tests/standards/soge_submitfiles/case8.txt"), "rb").read()