Skip to content

Commit cd6e89f

Browse files
committed
fix bug
1 parent ce77f49 commit cd6e89f

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

internal/cacct/cacct.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func QueryJob() util.CraneCmdError {
243243
taskInfo.Name,
244244
taskInfo.Partition,
245245
taskInfo.Account,
246-
strconv.FormatFloat(taskInfo.AllocatedResView.AllocatableRes.CpuCoreLimit*float64(taskInfo.NodeNum), 'f', 2, 64),
246+
strconv.FormatFloat(taskInfo.AllocatedResView.AllocatableRes.CpuCoreLimit, 'f', 2, 64),
247247
taskInfo.Status.String(),
248248
exitCode}
249249
}
@@ -328,7 +328,7 @@ func ProcessReqCPUs(task *protos.TaskInfo) string {
328328

329329
// AllocCPUs (c)
330330
func ProcessAllocCPUs(task *protos.TaskInfo) string {
331-
return strconv.FormatFloat(task.AllocatedResView.AllocatableRes.CpuCoreLimit*float64(task.NodeNum), 'f', 2, 64)
331+
return strconv.FormatFloat(task.AllocatedResView.AllocatableRes.CpuCoreLimit, 'f', 2, 64)
332332
}
333333

334334
// ElapsedTime (D)
@@ -411,8 +411,12 @@ func ProcessReqMemPerNode(task *protos.TaskInfo) string {
411411
}
412412

413413
// AllocMemPerNode (m)
414-
func ProcessAllocMemPerNode(task *protos.TaskInfo) string {
415-
return util.FormatMemToMB(task.AllocatedResView.AllocatableRes.MemoryLimitBytes)
414+
func ProcessAllocMemPerNode(task *protos.TaskInfo) string {
415+
if task.NodeNum == 0 {
416+
return "0M"
417+
}
418+
allocMemPerNode := task.AllocatedResView.AllocatableRes.MemoryLimitBytes / uint64(task.NodeNum)
419+
return util.FormatMemToMB(allocMemPerNode)
416420
}
417421

418422
// NodeNum (N)

internal/ccontrol/ccontrol.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,8 @@ func ShowJobs(jobIds string, queryAll bool) util.CraneCmdError {
428428
taskInfo.NodeNum, taskInfo.ReqResView.AllocatableRes.CpuCoreLimit*float64(taskInfo.NodeNum),
429429
util.FormatMemToMB(taskInfo.ReqResView.AllocatableRes.MemoryLimitBytes*uint64(taskInfo.NodeNum)),
430430
formatDeviceMap(taskInfo.ReqResView.DeviceMap),
431-
taskInfo.NodeNum, taskInfo.AllocatedResView.AllocatableRes.CpuCoreLimit*float64(taskInfo.NodeNum),
432-
util.FormatMemToMB(taskInfo.AllocatedResView.AllocatableRes.MemoryLimitBytes*uint64(taskInfo.NodeNum)),
431+
taskInfo.NodeNum, taskInfo.AllocatedResView.AllocatableRes.CpuCoreLimit,
432+
util.FormatMemToMB(taskInfo.AllocatedResView.AllocatableRes.MemoryLimitBytes),
433433
formatDeviceMap(taskInfo.AllocatedResView.DeviceMap),
434434
formatHostNameStr(util.HostNameListToStr(taskInfo.GetReqNodes())),
435435
formatHostNameStr(util.HostNameListToStr(taskInfo.GetExcludeNodes())),

internal/ceff/ceff.go

+17-8
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,17 @@ func PrintTaskInfo(taskInfo *protos.TaskInfo, records []*ResourceUsageRecord) er
333333
fmt.Printf("JobState: %v (exit code %d)\n", taskInfo.Status.String(), taskInfo.ExitCode)
334334
}
335335

336-
cpuTotal := taskInfo.AllocatedResView.AllocatableRes.CpuCoreLimit * float64(taskInfo.NodeNum)
336+
if taskInfo.NodeNum == 0 {
337+
return fmt.Errorf("the number of nodes is empty")
338+
}
339+
cpuTotal := taskInfo.AllocatedResView.AllocatableRes.CpuCoreLimit
337340
if math.Abs(cpuTotal-1) < 1e-9 {
338341
fmt.Printf("Cores: %.2f\n", cpuTotal)
339342
} else {
340343
fmt.Printf(
341344
"Nodes: %v\n"+
342345
"Cores per node: %.2f\n",
343-
taskInfo.NodeNum, taskInfo.AllocatedResView.AllocatableRes.CpuCoreLimit)
346+
taskInfo.NodeNum, cpuTotal / float64(taskInfo.NodeNum))
344347
}
345348

346349
if taskInfo.Status == protos.TaskStatus_Pending {
@@ -361,8 +364,9 @@ func PrintTaskInfo(taskInfo *protos.TaskInfo, records []*ResourceUsageRecord) er
361364

362365
// Calculate mem efficiency
363366
memEfficiency := 0.0
364-
mallocMemMbPerNode := float64(taskInfo.AllocatedResView.AllocatableRes.MemoryLimitBytes) / (1024 * 1024)
365-
totalMallocMemMb := mallocMemMbPerNode * float64(taskInfo.NodeNum)
367+
mallocMemMbPerNode := float64(taskInfo.AllocatedResView.AllocatableRes.MemoryLimitBytes) /
368+
float64(taskInfo.NodeNum) / (1024 * 1024)
369+
totalMallocMemMb := float64(taskInfo.ReqResView.AllocatableRes.MemoryLimitBytes)
366370
if totalMallocMemMb != 0 {
367371
memEfficiency = totalMemMb / totalMallocMemMb * 100
368372
}
@@ -398,7 +402,11 @@ func PrintTaskInfoInJson(taskInfo *protos.TaskInfo, records []*ResourceUsageReco
398402
return nil, fmt.Errorf("failed to get groupname for GID %d: %w", taskInfo.Gid, err)
399403
}
400404

401-
cpuTotal := taskInfo.AllocatedResView.AllocatableRes.CpuCoreLimit * float64(taskInfo.NodeNum)
405+
if taskInfo.NodeNum == 0 {
406+
return nil, fmt.Errorf("the number of nodes is empty")
407+
}
408+
cpuTotal := taskInfo.AllocatedResView.AllocatableRes.CpuCoreLimit
409+
coresPerNode := cpuTotal / float64(taskInfo.NodeNum)
402410
taskJsonInfo := &CeffTaskInfo{
403411
JobID: taskInfo.TaskId,
404412
QoS: taskInfo.Qos,
@@ -409,7 +417,7 @@ func PrintTaskInfoInJson(taskInfo *protos.TaskInfo, records []*ResourceUsageReco
409417
Account: taskInfo.Account,
410418
JobState: taskInfo.Status,
411419
Nodes: taskInfo.NodeNum,
412-
CoresPerNode: taskInfo.AllocatedResView.AllocatableRes.CpuCoreLimit,
420+
CoresPerNode: coresPerNode,
413421
}
414422

415423
if taskInfo.Status == protos.TaskStatus_Pending {
@@ -430,8 +438,9 @@ func PrintTaskInfoInJson(taskInfo *protos.TaskInfo, records []*ResourceUsageReco
430438

431439
// Calculate mem efficiency
432440
memEfficiency := 0.0
433-
mallocMemMbPerNode := float64(taskInfo.AllocatedResView.AllocatableRes.MemoryLimitBytes) / (1024 * 1024)
434-
totalMallocMemMb := mallocMemMbPerNode * float64(taskInfo.NodeNum)
441+
mallocMemMbPerNode := float64(taskInfo.ReqResView.AllocatableRes.MemoryLimitBytes) /
442+
float64(taskInfo.NodeNum) / (1024 * 1024)
443+
totalMallocMemMb := float64(taskInfo.ReqResView.AllocatableRes.MemoryLimitBytes)
435444
if totalMallocMemMb != 0 {
436445
memEfficiency = totalMemMb / totalMallocMemMb * 100
437446
}

internal/cqueue/cqueue.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ func ProcessAccount(task *protos.TaskInfo) string {
300300

301301
// 'c' group
302302
func ProcessAllocCpus(task *protos.TaskInfo) string {
303-
return strconv.FormatFloat(task.AllocatedResView.AllocatableRes.CpuCoreLimit * float64(task.NodeNum), 'f', 2, 64)
303+
return strconv.FormatFloat(task.AllocatedResView.AllocatableRes.CpuCoreLimit, 'f', 2, 64)
304304
}
305305

306306
// 'C' group
@@ -348,7 +348,11 @@ func ProcessNodeList(task *protos.TaskInfo) string {
348348

349349
// 'm' group
350350
func ProcessAllocMemPerNode(task *protos.TaskInfo) string {
351-
return util.FormatMemToMB(task.AllocatedResView.AllocatableRes.MemoryLimitBytes)
351+
if task.NodeNum == 0 {
352+
return "0M"
353+
}
354+
return util.FormatMemToMB(task.AllocatedResView.AllocatableRes.MemoryLimitBytes /
355+
uint64(task.NodeNum))
352356
}
353357

354358
// 'M' group

0 commit comments

Comments
 (0)