From e4d85e815fe023d20c7b48f97dc2d89512f0a644 Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Thu, 3 Aug 2023 00:56:33 -0700 Subject: [PATCH] add firstnodex policy --- .../policies/dfu_match_policy_factory.cpp | 4 +- .../policies/dfu_match_policy_factory.hpp | 1 + t/t3033-resource-nodex.t | 79 ++++++++----------- 3 files changed, 37 insertions(+), 47 deletions(-) diff --git a/resource/policies/dfu_match_policy_factory.cpp b/resource/policies/dfu_match_policy_factory.cpp index 34d74c87a..1e99f80d0 100644 --- a/resource/policies/dfu_match_policy_factory.cpp +++ b/resource/policies/dfu_match_policy_factory.cpp @@ -38,11 +38,13 @@ std::shared_ptr create_match_cb (const std::string &policy) std::shared_ptr matcher = nullptr; try { - if (policy == FIRST_MATCH) { + if (policy == FIRST_MATCH || policy == FIRST_NODEX_MATCH) { std::shared_ptr ptr = std::make_shared (); ptr->add_score_factor (std::string ("node"), 1, 10000); ptr->set_stop_on_k_matches (1); + if (policy == FIRST_NODEX_MATCH) + ptr->add_exclusive_resource_type ("node"); matcher = ptr; } else if (policy == HIGH_ID_FIRST) { matcher = std::make_shared (); diff --git a/resource/policies/dfu_match_policy_factory.hpp b/resource/policies/dfu_match_policy_factory.hpp index cf377f6f6..59742e5a2 100644 --- a/resource/policies/dfu_match_policy_factory.hpp +++ b/resource/policies/dfu_match_policy_factory.hpp @@ -25,6 +25,7 @@ namespace Flux { namespace resource_model { const std::string FIRST_MATCH = "first"; +const std::string FIRST_NODEX_MATCH = "firstnodex"; const std::string HIGH_ID_FIRST = "high"; const std::string LOW_ID_FIRST = "low"; const std::string LOW_NODE_FIRST = "lonode"; diff --git a/t/t3033-resource-nodex.t b/t/t3033-resource-nodex.t index d7b233d83..c6aafe907 100755 --- a/t/t3033-resource-nodex.t +++ b/t/t3033-resource-nodex.t @@ -9,7 +9,36 @@ exp_dir="${SHARNESS_TEST_SRCDIR}/data/resource/expected/nodex" grugs="${SHARNESS_TEST_SRCDIR}/data/resource/grugs/small.graphml" query="../../resource/utilities/resource-query" -# +# Takes policy and cmd outfile prefix +run_tests_with_policy() { + pol=$1 + prefix=$2 + + cmds001="${cmd_dir}/cmds01.in" + test001_desc="allocate 7 jobs with node-level constraint (pol=$pol)" + test_expect_success "${test001_desc}" ' + sed "s~@TEST_SRCDIR@~${SHARNESS_TEST_SRCDIR}~g" ${cmds001} > cmds001 && + ${query} -L ${grugs} -S CA -P $pol -t ${prefix}1.R.out < cmds001 && + test_cmp ${prefix}1.R.out ${exp_dir}/${prefix}1.R.out + ' + + cmds002="${cmd_dir}/cmds02.in" + test002_desc="allocate 7 jobs with no node-level constraint (pol=$pol)" + test_expect_success "${test002_desc}" ' + sed "s~@TEST_SRCDIR@~${SHARNESS_TEST_SRCDIR}~g" ${cmds002} > cmds002 && + ${query} -L ${grugs} -S CA -P $pol -t ${prefix}2.R.out < cmds002 && + test_cmp ${prefix}2.R.out ${exp_dir}/${prefix}2.R.out + ' + + cmds003="${cmd_dir}/cmds03.in" + test003_desc="match allocate 7 jobs -- last fails (pol=$pol)" + test_expect_success "${test003_desc}" ' + sed "s~@TEST_SRCDIR@~${SHARNESS_TEST_SRCDIR}~g" ${cmds003} > cmds003 && + ${query} -L ${grugs} -S CA -P $pol -t ${prefix}3.R.out < cmds003 && + test_cmp ${prefix}3.R.out ${exp_dir}/${prefix}3.R.out + ' +} + # Selection Policy -- High node first with node exclusivity (-P hinodex) # Selection behavior is identical to hinode except that # it marks each selected node as exclusive even if the @@ -25,29 +54,7 @@ query="../../resource/utilities/resource-query" # again all 36 cores from the current available highest node. # -cmds001="${cmd_dir}/cmds01.in" -test001_desc="allocate 7 jobs with node-level constraint (pol=hinodex)" -test_expect_success "${test001_desc}" ' - sed "s~@TEST_SRCDIR@~${SHARNESS_TEST_SRCDIR}~g" ${cmds001} > cmds001 && - ${query} -L ${grugs} -S CA -P hinodex -t 001.R.out < cmds001 && - test_cmp 001.R.out ${exp_dir}/001.R.out -' - -cmds002="${cmd_dir}/cmds02.in" -test002_desc="allocate 7 jobs with no node-level constraint (pol=hinodex)" -test_expect_success "${test002_desc}" ' - sed "s~@TEST_SRCDIR@~${SHARNESS_TEST_SRCDIR}~g" ${cmds002} > cmds002 && - ${query} -L ${grugs} -S CA -P hinodex -t 002.R.out < cmds002 && - test_cmp 002.R.out ${exp_dir}/002.R.out -' - -cmds003="${cmd_dir}/cmds03.in" -test003_desc="match allocate 7 jobs -- last fails (pol=hinodex)" -test_expect_success "${test003_desc}" ' - sed "s~@TEST_SRCDIR@~${SHARNESS_TEST_SRCDIR}~g" ${cmds003} > cmds003 && - ${query} -L ${grugs} -S CA -P hinodex -t 003.R.out < cmds003 && - test_cmp 003.R.out ${exp_dir}/003.R.out -' +run_tests_with_policy hinodex 00 # # Selection Policy -- Low node first with node exclusivity (-P lonodex) @@ -65,28 +72,8 @@ test_expect_success "${test003_desc}" ' # again all 36 cores from the current available lowest node. # -cmds011="${cmd_dir}/cmds01.in" -test011_desc="allocate 7 jobs with node-level constraint (pol=lonodex)" -test_expect_success "${test011_desc}" ' - sed "s~@TEST_SRCDIR@~${SHARNESS_TEST_SRCDIR}~g" ${cmds011} > cmds011 && - ${query} -L ${grugs} -S CA -P lonodex -t 011.R.out < cmds011 && - test_cmp 011.R.out ${exp_dir}/011.R.out -' - -cmds012="${cmd_dir}/cmds02.in" -test012_desc="allocate 7 jobs with no node-level constraint (pol=lonodex)" -test_expect_success "${test012_desc}" ' - sed "s~@TEST_SRCDIR@~${SHARNESS_TEST_SRCDIR}~g" ${cmds012} > cmds012 && - ${query} -L ${grugs} -S CA -P lonodex -t 012.R.out < cmds012 && - test_cmp 012.R.out ${exp_dir}/012.R.out -' +run_tests_with_policy lonodex 01 -cmds013="${cmd_dir}/cmds03.in" -test013_desc="match allocate 7 jobs -- last fails (pol=lonodex)" -test_expect_success "${test013_desc}" ' - sed "s~@TEST_SRCDIR@~${SHARNESS_TEST_SRCDIR}~g" ${cmds013} > cmds013 && - ${query} -L ${grugs} -S CA -P lonodex -t 013.R.out < cmds013 && - test_cmp 013.R.out ${exp_dir}/013.R.out -' +run_tests_with_policy firstnodex 00 test_done