diff --git a/job_submit.lua b/job_submit.lua index db68f54..3ec89f3 100644 --- a/job_submit.lua +++ b/job_submit.lua @@ -1,92 +1,92 @@ --########################################################################-- -- -- Load billing_cost_estimate parameters (can be overriden in rates_file) -- --########################################################################-- CONF_DIR = '/etc/slurm/job_submit' CONF_FILES = {'job_submit.conf', 'cluster.conf', 'rates.conf'} for index, file in ipairs(CONF_FILES) do filetoload = CONF_DIR.."/"..file file_fh = io.open(filetoload, "r") if file_fh == nil then slurm.log_info("slurm_job_modify: No readable %s found!", filetoload) else io.close(file_fh) dofile(filetoload) end end --- require fonctions verbose_mode, track_gres, scitas_cost.lua, partition_setting.lua --- if FX_VERBOSE then require('job_submit_fx/verbose_mode.lua') end if FX_TRACK_GRES then require('job_submit_fx/track_gres.lua') end if FX_SCITAS_COST then require('job_submit_fx/scitas_cost.lua') end if FX_PARTITION then require('job_submit_fx/partition_setting.lua') end if FX_FORCE_ACCOUNT then require('job_submit_fx/force_account.lua') end require('job_submit_fx/validate_job.lua') function slurm_job_submit(job_desc, part_list, submit_uid) --- Verbose mode --- --- To enable verbose mode, you must set the verbose_mode variable to 1 if FX_VERBOSE then verbose_mode(job_desc) end if FX_PARTITION then local partition = partition_setting (job_desc, submit_uid, INFINITE, SEVENTY, PARALLEL_PARTITION, SERIAL_PARTITION) if job_desc.partition ~= partition then job_desc.partition = partition slurm.log_info("slurm_job_modify: for user %u , setting partition: %s", submit_uid, partition) end end if FX_TRACK_GRES then status = track_gres(job_desc, submit_uid) if status ~= 0 then return status end end if FX_SCITAS_COST then - scitas_cost(job_desc, CPU_COST, GPU_COST, CORES_PER_NODE, GPUS_PER_NODE, DEFAULT_WTIME, DEFAULT_PARTITION, PARALLEL_PARTITION, SERIAL_PARTITION, submit_uid) + scitas_cost(job_desc, submit_uid) end if FX_FORCE_ACCOUNT then force_account(job_desc) end validate_job(job_desc) return slurm.SUCCESS end -- The other required function function slurm_job_modify(job_desc, job_rec, part_list, modify_uid) return slurm.SUCCESS end slurm.log_info("job_submit_plugin initialized") return slurm.SUCCESS diff --git a/job_submit_fx/billing_cost_estimate.lua b/job_submit_fx/billing_cost_estimate.lua index 1c39c31..4ba36ff 100644 --- a/job_submit_fx/billing_cost_estimate.lua +++ b/job_submit_fx/billing_cost_estimate.lua @@ -1,148 +1,145 @@ -- Function billing_cost_estimate to display job cost -- -function billing_cost_estimate (job_desc, cpu_cost, gpu_cost, corespernode, gpuspernode, defaultwtime, defaultpartition, parallel, serial, submit_uid) - +function billing_cost_estimate (job_desc, submit_uid) -- Initializing local variables require('job_submit_fx/scitas_debug.lua') local gputres = nil local gpu = nil local chf = nil local timeinsec = nil local nodetres = job_desc.min_nodes local cputres = job_desc.min_cpus local wtime = job_desc.time_limit local partition = job_desc.partition local ntaskpernode = job_desc.ntasks_per_node local costunit = "cpu" local debugmode = scitas_debug(job_desc) - local infisixteen = 65534 - local infithirtytwo = 4294967294 + local infisixteen = 2^16 - 1 + local infithirtytwo = slurm.INFINITE - 1 local arrayindex = 1 local freeparts = {'build', 'debug'} local isfree = 0 - if partition == nil then - partition = defaultpartition + partition = DEFAULT_PARTITION end -- Free partitions for i, fpname in ipairs(freeparts) do if partition == fpname then isfree = 1 end end if job_desc.array_inx ~= nil then ak, av = string.match(job_desc.array_inx, "(.*)%-(.*)") if tonumber(ak) ~= nil and tonumber(av) ~= nil then arrayindex = tonumber(av) - tonumber(ak) + 1 end end if job_desc.gres ~= nil then gputres = string.match(job_desc.gres, "gpu.[0-9]+") end -- Convert time in seconds if wtime == nil or wtime == infithirtytwo or wtime == infisixteen then - timeinsec = defaultwtime + timeinsec = DEFAULT_WTIME else timeinsec = wtime * 60 end -- Update cost unit if user request GPUs if gputres ~= nil then gk, gv = string.match(gputres, "(.*)%:(.*)") gpu=tonumber(gv) if gpu == nil or gpu < 1 then costunit = nil else costunit = "gpu" end end -- -- User does not define the number of nodes -- if nodetres == infithirtytwo or nodetres == infisixteen or nodetres == nil then - if string.match(partition, serial) then + if string.match(partition, SERIAL_PARTITION) then node = 1 else node = 0 end else node = nodetres end - -- CPUs -- First case: user does not define the number of CPUs -- if cputres == infithirtytwo or cputres == infisixteen or cputres == nil then - cpu = corespernode + cpu = CORES_PER_NODE -- -- Second case: user defines the number of CPUs -- else cpu = cputres end -- -- Special cases -- - if string.match(partition, parallel) then - cpu = corespernode - if tonumber(cputres) >= tonumber(corespernode) and node == 0 then + if string.match(partition, PARALLEL_PARTITION) then + cpu = CORES_PER_NODE + if tonumber(cputres) >= tonumber(CORES_PER_NODE) and node == 0 then if ntaskpernode == infithirtytwo or ntaskpernode == nil or ntaskpernode == infisixteen then - node = math.ceil(tonumber(cputres)/tonumber(corespernode)) + node = math.ceil(tonumber(cputres)/tonumber(CORES_PER_NODE)) else node = math.ceil(tonumber(cputres)/tonumber(ntaskpernode)) end end end -- -- Calculating price -- if isfree == 1 then chf = 0 - else + else if costunit == "cpu" then if cpu == infithirtytwo or node == infithirtytwo then slurm.log_info("billing::: cannot determine the values to calculate the price") else - chf = cpu * node * cpu_cost * timeinsec * arrayindex + chf = cpu * node * CPU_COST * timeinsec * arrayindex end elseif costunit == "gpu" then if node == 0 then - node = math.ceil(tonumber(gpu)/tonumber(gpuspernode)) + node = math.ceil(tonumber(gpu)/tonumber(GPUS_PER_NODE)) end - chf = gpu * node * gpu_cost * timeinsec * arrayindex + chf = gpu * node * GPU_COST * timeinsec * arrayindex else slurm.log_info("billing::: cannot determine the unit type") end end -- -- Print the price -- -- if chf ~= nil then if debugmode == 1 then - slurm.log_user("billing::: cpu: "..cpu) - slurm.log_user("billing::: gpu: "..gpu) - slurm.log_user("billing::: node: "..node) - slurm.log_user("billing::: timeinsec: "..timeinsec) + slurm.log_user("billing::: cpu: "..(cpu or 'nil')) + slurm.log_user("billing::: gpu: "..(gpu or 'nil')) + slurm.log_user("billing::: node: "..(node or 'nil')) + slurm.log_user("billing::: timeinsec: "..(timeinsec or 'nil')) end slurm.log_user("The estimated cost of this job is CHF "..string.format("%.2f",chf)) slurm.log_info("billing::: cost "..submit_uid.."|"..chf) else slurm.log_info("billing::: cannot calculate the price") end end diff --git a/job_submit_fx/scitas_cost.lua b/job_submit_fx/scitas_cost.lua index 7467853..93af458 100644 --- a/job_submit_fx/scitas_cost.lua +++ b/job_submit_fx/scitas_cost.lua @@ -1,12 +1,12 @@ -function scitas_cost (job_desc, cpu_cost, gpu_cost, corespernode, gpuspernode, defaultwtime, defaultpartition, parallel, serial, submit_uid) +function scitas_cost (job_desc, submit_uid) if job_desc.comment ~= nil then if string.match(job_desc.comment, "scitas.cost") then require('job_submit_fx/billing_cost_estimate.lua') - billing_cost_estimate(job_desc, cpu_cost, gpu_cost, corespernode, gpuspernode, defaultwtime, defaultpartition, parallel, serial, submit_uid) + billing_cost_estimate(job_desc, submit_uid) else return 0 end else return 0 end end