-
Notifications
You must be signed in to change notification settings - Fork 3
/
slurm_showq.cpp
1185 lines (951 loc) · 33.5 KB
/
slurm_showq.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//-------------------------------------------------------------------------
// Copyright (c) 2012 The Regents of the University of Texas System.
// All rights reserved.
//
// Redistribution and use in source and binary forms are permitted
// provided that the above copyright notice and this paragraph are
// duplicated in all such forms and that any documentation,
// advertising materials, and other materials related to such
// distribution and use acknowledge that the software was developed by
// the University of Texas. The name of the University may not be
// used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
// WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
//-------------------------------------------------------------------------
// A SLURM derived showq for summarizing user jobs.
//
// Originally: 7/29/2012 (refactor of original LSF version)
// Karl W. Schulz- Texas Advanced Computing Center ([email protected])
//
// Last update: Si Liu on 03/07/2020
// $Id: slurm_showq.cpp 2020-03-07 siliu $
//-------------------------------------------------------------------------*/
#include "slurm_showq.h"
void Slurm_Showq::query_running_jobs()
{
char *user, *starttime, *shorttime, *pendreason, *endtime, *submittime;
time_t current_time, remain_time;
char jobuser_short [256];
char jobname_short [256];
char queuename_short[256];
int i, j, status;
int rjobs = 0;
int rprocs = 0;
int rnodes = 0;
int dprocs, dnodes;
int ijobs, bjobs, error_jobs;
int running_jobs;
int reserv_procs;
int numHosts = 1;
long hours_max, secs_max;
long hours_remain, mins_remain, secs_remain;
int num_pending_jobs = 0;
int num_completing_jobs = 0;
int idle_jobs = 0;
int blocked_jobs = 0;
int num_closed = 0;
char queuename[8];
char current_user[256];
int num_nodes;
long int time1, time2;
// const int total_avail_procs = 5760*16;
std::vector<uint32_t> completing_jobs; // list of jobs in completing state
std::vector<uint32_t> pending_jobs; // list of jobs in pending state
std::vector<uint32_t> errored_jobs; // list of jobs with a problem
typedef struct koomie_job_struct
{
int jobId;
char *submittime;
long hours_remain;
long mins_remain;
long secs_remain;
char *jobname;
char *user;
char *queue;
int numProcessors;
int ptile;
int iflag :4; /* iflag = 0: new job */
/* iflag = 1: idle */
/* iflag = 2: held */
/* iflag = 3: blocked */
} koomie_job_struct;
koomie_job_struct *Pend_jobs;
if (named_user_jobs_only)
strncpy(current_user,named_user.c_str(),255);
else
strncpy(current_user,getusername(),255);
bool local_user_jobs_only=(user_jobs_only || named_user_jobs_only);
if(local_user_jobs_only)
printf("\nSUMMARY OF JOBS FOR USER: <%s>\n\n",current_user);
//----------------
// Query all jobs
//---------------
job_info_msg_t *job_ptr = NULL;
if( slurm_load_jobs( (time_t) NULL, &job_ptr, SHOW_ALL) )
{
printf("[Error]: unable to query SLURM jobs\n");
exit(10);
}
//slurm_print_job_info_msg(stdout,job_ptr,0);
running_jobs = 1;
std::string userString;
/*--------------
* showq Header
*--------------*/
if(running_jobs)
{
printf("ACTIVE JOBS--------------------\n");
if(long_listing)
{
printf("JOBID JOBNAME USERNAME STATE CORES NODES QUEUE REMAINING STARTTIME\n");
printf("===================================================================================================\n");
}
else
{
printf("JOBID JOBNAME USERNAME STATE NODES REMAINING STARTTIME\n");
printf("================================================================================\n");
}
/*-------------------------------
* 1st: Display all running jobs
*-------------------------------*/
for(int i=0; i<job_ptr->record_count;i++)
{
job_info_t * job;
job = &job_ptr->job_array[i];
// get username string
userString = uid_to_string(job->user_id);
// DEBUGGING missing jobs
// if (job->job_id == 6284384)
// printf("\nI catch you!!! reason=%d \n", job->state_reason);
// keep track of pending jobs...
if(job->job_state == JOB_PENDING)
{
num_pending_jobs++;
pending_jobs.push_back(i);
continue;
}
current_time = time(NULL);
secs_max = job->time_limit*60; // max runtime (converted to secs)
remain_time = (time_t)difftime(secs_max+job->start_time,current_time);
// keep track of completing jobs - those which have exceeded
// their runlimit by a given threshold are flagged as
// errored.
if(job->job_state & JOB_COMPLETING)
{
//ignore non-user jobs with "-u" flag
if ((local_user_jobs_only) &&
(strcmp(current_user,uid_to_string(job->user_id).c_str()) != 0) )
continue;
completing_jobs.push_back(i);
// allow 5 minute grace window
if(remain_time < 300)
continue;
errored_jobs.push_back(i);
continue;
}
// only displaying running jobs currently...
if( job->job_state != JOB_RUNNING )
continue;
if ((local_user_jobs_only) &&
(strcmp(current_user,uid_to_string(job->user_id).c_str()) != 0) )
continue;
// Gather time info
starttime = strdup(ctime( &job->start_time));
starttime[strlen(starttime)-1] = '\0';
hours_remain = remain_time/3600;
mins_remain = (remain_time-hours_remain*3600)/60;
secs_remain = (remain_time - hours_remain*3600 - mins_remain*60);
if(hours_remain < 0 || mins_remain < 0 || secs_remain < 0)
{
printf("[Warn]: runlimit exhausted: runningpending job reason = %i\n",job->state_reason);
continue;
}
// Display job info
printf("%-10i", job->job_id);
strncpy(jobname_short,job->name,10);
jobname_short[10] = '\0';
printf("%-11s",jobname_short);
strncpy(jobuser_short,uid_to_string(job->user_id).c_str(),14);
jobuser_short[14] = '\0';
printf("%-14s", jobuser_short);
printf("%-8s","Running");
if(long_listing)
{
printf("%-6i ",job->num_cpus);;
}
//print node number
printf("%-5i",job->num_nodes);
//print queue
if(long_listing)
{
//printf("%-4i",job->num_nodes);
//printf("%-4i",6000);
strncpy(queuename_short,job->partition,14);
queuename_short[14] = '\0';
printf(" %-14s",queuename_short);
}
printf(" %2i:",hours_remain);
if(mins_remain < 10)
printf("0%1i:",mins_remain);
else
printf("%2i:",mins_remain);
if(secs_remain < 10)
printf("0%1i ",secs_remain);
else
printf("%2i ",secs_remain);
shorttime = (char *)calloc(20,sizeof(char));
strncpy(shorttime,starttime,19);
shorttime[19] = '\0';
printf("%s",shorttime);
printf("\n");
free(starttime);
free(shorttime);
rjobs++;
rprocs += job->num_cpus;
rnodes += job->num_nodes;
} // end loop over slurm jobs
/* Running Job summary*/
if(local_user_jobs_only)
{
//printf("\nYou have %3i Active jobs utilizing: %6i of %6i Processors (%4.2f%%)\n",rjobs,rprocs,
//total_avail_procs,(float)100.*rprocs/total_avail_procs);
}
else
{
printf("\n");
if(rjobs == 1)
printf(" %6i active job ",rjobs);
else
printf(" %6i active jobs ",rjobs);
if(show_utilization)
printf(": %4i of %4i hosts (%6.2f %%)\n",rnodes,total_avail_nodes,(float)100.*rnodes/total_avail_nodes);
else
printf("\n");
}
}
//---------------------------------------------------------------------
// 2nd: Display pending jobs; 1st come idle jobs waiting for free
// resources, then come blocked jobs
// ---------------------------------------------------------------------
if(pending_jobs.size() > 0)
{
printf("\nWAITING JOBS------------------------\n");
if(long_listing)
{
printf("JOBID JOBNAME USERNAME STATE CORES NODES QUEUE WCLIMIT QUEUETIME\n");
printf("==================================================================================================\n");
}
else
{
printf("JOBID JOBNAME USERNAME STATE NODES WCLIMIT QUEUETIME\n");
printf("================================================================================\n");
}
for(int i=0; i<pending_jobs.size();i++)
{
job_info_t * job;
job = &job_ptr->job_array[pending_jobs[i]];
if(job->job_state != JOB_PENDING)
continue;
if ((local_user_jobs_only) &&
(strcmp(current_user,uid_to_string(job->user_id).c_str()) != 0) )
continue;
// Si Liu in Dec 2015:
// Update the new SLURM PENDING_REASONS since SLURM 15:
// Si Liu in July 2019
// Update the new SLURM QOS Qaiting REASONS for SLURM 19
//DEBUGGING
//printf("job id=%d reason= %d\n", job->job_id, job->state_reason);
// For the following reasons, the job will not automatically run (This includes both blocked jobs and errored jobs!)
if(
job->state_reason == WAIT_DEPENDENCY || /* 2, dependent job has not completed */
job->state_reason == WAIT_PART_NODE_LIMIT || /* 4 request exceeds partition node limit */
job->state_reason == WAIT_PART_TIME_LIMIT || /* 5 request exceeds partition time limit */
job->state_reason == WAIT_HELD || /* 8, job is held by administrator */
job->state_reason == WAIT_TIME || /* 9, job waiting for specific begin time */
job->state_reason == WAIT_RESERVATION || /* 14, reservation not available */
job->state_reason == WAIT_NODE_NOT_AVAIL || /* 15, required node is DOWN or DRAINED */
job->state_reason == WAIT_HELD_USER || /* 16, job is held by user */
job->state_reason == FAIL_DOWN_PARTITION || /* 18, partition for job is DOWN */
job->state_reason == FAIL_DOWN_NODE || /* 19, some node in the allocation failed */
job->state_reason == FAIL_BAD_CONSTRAINTS || /* 20, constraints can not be satisfied */
job->state_reason == WAIT_DEP_INVALID || /* 38, Dependency condition invalid or never*/
(job->state_reason >= WAIT_QOS_MAX_CPU_PER_JOB && job->state_reason <= WAIT_QOS_MIN_CPU) //QOS WAIT47-55
)
{
// printf("DEBUGGING: job id=%d reason= %d\n added to block", job->job_id, job->state_reason);
// printf("\n\nI am still blocked!\n\n");
blocked_jobs++;
continue;
}
// Si Liu in Dec 2015:
// For the following reasons, the job will finally run without extra manipulation (Jobs are reported as Waiting!)
if(
job->state_reason == WAIT_NO_REASON || /* 0, not set or job not pending */
job->state_reason == WAIT_PRIORITY || /* 1, higher priority jobs exist */
job->state_reason == WAIT_RESOURCES || /* 3, required resources not available */
job->state_reason == WAIT_PART_DOWN || /* 6, requested partition is down */
job->state_reason == WAIT_PART_INACTIVE /* 7, requested partition is inactive */
)
{
idle_jobs++;
}
else
{
printf("[Warn]: unknown job state - pending job reason = %i\n",job->state_reason);
continue;
}
//DEBUGGING
//printf("IDLE jobs: job id=%d reason= %d\n", job->job_id, job->state_reason);
// Display job info
printf("%-10i", job->job_id);
strncpy(jobname_short,job->name,10);
jobname_short[10] = '\0';
printf("%-11s",jobname_short);
strncpy(jobuser_short,uid_to_string(job->user_id).c_str(),14);
jobuser_short[14] = '\0';
printf("%-14s", jobuser_short);
printf("%-8s","Waiting");
if(long_listing)
{
printf("%-5i ",job->num_cpus);
}
printf("%-5i",job->num_nodes);
if(long_listing)
{
// printf("%-4i ",job->num_nodes);
strncpy(queuename_short,job->partition,14);
queuename_short[14] = '\0';
printf(" %-14s",queuename_short);
}
secs_max = job->time_limit*60; // max runtime (converted to secs)
hours_remain = secs_max/3600;
mins_remain = (secs_max-hours_remain*3600)/60;
secs_remain = (secs_max - hours_remain*3600 - mins_remain*60);
printf(" %2i:",hours_remain);
if(mins_remain < 10)
printf("0%1i:",mins_remain);
else
printf("%2i:",mins_remain);
if(secs_remain < 10)
printf("0%1i ",secs_remain);
else
printf("%2i ",secs_remain);
submittime = strdup(ctime( &job->submit_time));
shorttime = (char *)calloc(20,sizeof(char));
strncpy(shorttime,submittime,19);
printf("%s",shorttime);
printf("\n");
free(submittime);
free(shorttime);
} // end loop over slurm jobs
} // end for pending jobs
if(blocked_jobs > 0)
{
printf("\nBLOCKED JOBS--\n");
if(long_listing)
{
printf("JOBID JOBNAME USERNAME STATE CORES NODES QUEUE WCLIMIT QUEUETIME\n");
printf("==================================================================================================\n");
}
else
{
printf("JOBID JOBNAME USERNAME STATE NODES WCLIMIT QUEUETIME\n");
printf("================================================================================\n");
}
for(int i=0; i<pending_jobs.size();i++)
{
job_info_t * job;
job = &job_ptr->job_array[pending_jobs[i]];
if(job->job_state != JOB_PENDING)
continue;
// if (job->job_id == 6284384)
// printf("\n\nI am still alive!\n\n");
if ((local_user_jobs_only) &&
(strcmp(current_user,uid_to_string(job->user_id).c_str()) != 0) )
continue;
// DEBUGGING info
// printf("job id=%d reason= %d\n", job->job_id, job->state_reason);
//Si Liu in Dec 2015:
//We updated this in version 15 or later:
//The list of known errored jobs:
if(
job->state_reason == WAIT_PART_NODE_LIMIT || /* 4 request exceeds partition node limit */
job->state_reason == WAIT_PART_TIME_LIMIT || /* 5 request exceeds partition time limit */
job->state_reason == FAIL_BAD_CONSTRAINTS || /* 20, constraints can not be satisfied */
job->state_reason == WAIT_DEP_INVALID /* 38, Dependency condition invalid or never*/
)
{
// DEBUGGING info
// printf("\n\nI am still alive!\n\n");
errored_jobs.push_back(pending_jobs[i]);
// DEBUGGING printf("\n\ncurrent error job size %d new job id %d \n\n",errored_jobs.size(),job->job_id);
continue;
}
//Si Liu in Mar 2020:
//Waiting Priority jobs -> alaready displayed in WAITING
if(
job->state_reason == WAIT_NO_REASON || /* 0, not set or job not pending */
job->state_reason == WAIT_PRIORITY || /* 1, higher priority jobs exist */
job->state_reason == WAIT_RESOURCES || /* 3, required resources not available */
job->state_reason == WAIT_PART_DOWN || /* 6, requested partition is down */
job->state_reason == WAIT_PART_INACTIVE /* 7, requested partition is inactive */
)
continue;
if(
job->state_reason != WAIT_DEPENDENCY && /* 2 dependent job has not completed */
job->state_reason != WAIT_HELD && /* 8 job is held by administrator */
job->state_reason != WAIT_TIME && /* 9 job waiting for specific begin time */
job->state_reason != WAIT_RESERVATION && /* 14 reservation not available */
job->state_reason != WAIT_NODE_NOT_AVAIL && /* 15 required node is DOWN or DRAINED */
job->state_reason != WAIT_HELD_USER && /* 16 job is held by user */
job->state_reason != FAIL_DOWN_PARTITION && /* 18 partition for job is DOWN */
job->state_reason != FAIL_DOWN_NODE && /* 19 some node in the allocation failed */
//New extr QOS wait since Slurm 19 (07/07/2019)
job->state_reason < WAIT_QOS_MAX_CPU_PER_JOB &&
job->state_reason > WAIT_QOS_MIN_CPU
)
{
continue;
}
// Display job info
printf("%-10i", job->job_id);
strncpy(jobname_short,job->name,10);
jobname_short[10] = '\0';
printf("%-11s",jobname_short);
strncpy(jobuser_short,uid_to_string(job->user_id).c_str(),14);
jobuser_short[14] = '\0';
printf("%-14s", jobuser_short);
// printf("%-8s","Blocked");
switch( job->state_reason )
{
case WAIT_DEPENDENCY: //2
printf("%-8s","WaitDep");
break;
case WAIT_HELD: //8
printf("%-8s","HeldAdm");
break;
case WAIT_TIME: //9
printf("%-8s","WaitTim");
break;
case WAIT_RESERVATION: //14
printf("%-8s","WaitRes");
break;
case WAIT_NODE_NOT_AVAIL: //15
printf("%-8s","WaitNod");
break;
case WAIT_HELD_USER: //16
printf("%-8s","HeldUsr");
break;
case FAIL_DOWN_PARTITION: //18
printf("%-8s","DownPar");
break;
case FAIL_DOWN_NODE: //19
printf("%-8s","DownNode");
break;
case WAIT_QOS_MAX_CPU_PER_JOB ... WAIT_QOS_MIN_CPU: //47 - 55 QOS wait
printf("%-8s","WaitQOS");
break;
default:
printf("%-8s","Blocked");
break;
}
if(long_listing)
{
printf("%-6i ",job->num_cpus);
}
printf("%-5i",job->num_nodes);
if(long_listing)
{
strncpy(queuename_short,job->partition,14);
queuename_short[14] = '\0';
printf(" %-14s",queuename_short);
}
secs_max = job->time_limit*60; // max runtime (converted to secs)
hours_remain = secs_max/3600;
mins_remain = (secs_max-hours_remain*3600)/60;
secs_remain = (secs_max - hours_remain*3600 - mins_remain*60);
printf(" %2i:",hours_remain);
if(mins_remain < 10)
printf("0%1i:",mins_remain);
else
printf("%2i:",mins_remain);
if(secs_remain < 10)
printf("0%1i ",secs_remain);
else
printf("%2i ",secs_remain);
submittime = strdup(ctime( &job->submit_time));
shorttime = (char *)calloc(20,sizeof(char));
strncpy(shorttime,submittime,19);
printf("%s",shorttime);
printf("\n");
free(submittime);
free(shorttime);
} // end loop over jobs
}
//-----------------------------------------------------
// 4th: Summarize completing/errored jobs
//----------------------------------------------------
if(errored_jobs.size() > 0)
{
//printf("errored job size %d\n", errored_jobs.size());
printf("\nCOMPLETING/ERRORED JOBS-------------\n");
printf("JOBID JOBNAME USERNAME STATE NODES WCLIMIT QUEUETIME\n");
printf("================================================================================\n");
for(int i=0; i<errored_jobs.size();i++)
{
job_info_t * job;
job = &job_ptr->job_array[errored_jobs[i]];
// printf("\n\n stored error job size %d stored job id %d \n\n",errored_jobs.size(),job->job_id);
current_time = time(NULL);
secs_max = job->time_limit*60; // max runtime (converted to secs)
remain_time = (time_t)difftime(secs_max+job->start_time,current_time);
starttime = strdup(ctime( &job->start_time));
starttime[strlen(starttime)-1] = '\0';
hours_remain = remain_time/3600;
mins_remain = (remain_time-hours_remain*3600)/60;
secs_remain = (remain_time - hours_remain*3600 - mins_remain*60);
/* only show leading minus sign */
// debug:
//if (job->job_id == 6284384)
// printf("\n\nI am still alive!\n\n");
// if (job->job_id == 6302330)
// {printf ("start_time: %d, secs_max : %d \n", job->start_time, secs_max);
// printf ("current time: %d , remain time: %d \n ", current_time, remain_time);
// }
if(mins_remain < 0)
mins_remain = -mins_remain;
if(secs_remain < 0)
secs_remain = -secs_remain;
strncpy(jobname_short,job->name,10);
jobname_short[10] = '\0';
strncpy(jobuser_short,uid_to_string(job->user_id).c_str(),14);
jobuser_short[14] = '\0';
printf("%-10i", job->job_id);
printf("%-11s",jobname_short);
printf("%-14s", jobuser_short);
// printf("%-8s","Complte");
switch(job->state_reason)
{
case WAIT_PART_NODE_LIMIT: /* 4 request exceeds partition node limit */
printf("%-8s","ErrNode");
break;
case WAIT_PART_TIME_LIMIT: /* 5 request exceeds partition time limit */
printf("%-8s","ErrTime");
break;
case FAIL_BAD_CONSTRAINTS: /* 20, constraints can not be satisfied */
printf("%-8s","ErrCons");
break;
case WAIT_DEP_INVALID: /* 38, Dependency condition invalid or never*/
printf("%-8s","ErrDep");
break;
default:
printf("%-8s","Complte");
break;
}
printf("%-5i ",job->num_nodes);
if (hours_remain>0)
{
printf(" %2i:",hours_remain);
if(mins_remain < 10)
printf("0%1i:",mins_remain);
else
printf("%2i:",mins_remain);
if(secs_remain < 10)
printf("0%1i ",secs_remain);
else
printf("%2i ",secs_remain);
}
else
{
printf(" Unknown ");
}
shorttime = (char *)calloc(20,sizeof(char));
strncpy(shorttime,starttime,19);
shorttime[19] = '\0';
printf("%s",shorttime);
printf("\n");
free(starttime);
free(shorttime);
} // end loop over errored jobs
}
/*----------
* Summary
*----------*/
printf("\nTotal Jobs: %-4i Active Jobs: %-4i Idle Jobs: %-4i "
"Blocked Jobs: %-4i\n",rjobs+idle_jobs+blocked_jobs,
rjobs,idle_jobs,blocked_jobs);
//
// /*------------------------------
// * Query advanced reservations
// *------------------------------*/
//
// resInfo = lsb_reservationinfo(NULL, &resvNumbers, 0);
//
// if(resvNumbers > 0)
// {
//
// printf("\nADVANCED RESERVATIONS----------\n");
// printf("RESV ID PROC RESERVATION WINDOW\n");
//
// for(i=0;i<resvNumbers;i++)
// {
// sscanf(resInfo[i].timeWindow,"%ld-%ld",&time1,&time2);
//
// /* Weed out reservations that are a long way out */
//
// if( (difftime(time1,time(NULL))) > RES_LEAD_WINDOW && !show_all_reserv)
// continue;
//
// starttime = strdup(ctime(&time1));
// endtime = strdup(ctime(&time2));
// starttime[strlen(starttime)-1] = '\0';
// endtime[strlen(endtime)-1] = '\0';
//
// /* Count up the number of reserved processors */
//
// reserv_procs = 0;
// for(j=0;j<resInfo[i].numRsvHosts;j++)
// reserv_procs += resInfo[i].rsvHosts[j].numRsvProcs;
//
// printf("%-10s %4i %s - %s\n",resInfo[i].rsvId,
// reserv_procs,starttime,endtime);
//
//
//
// free(starttime);
// free(endtime);
//
// }
// }
// clean-up time
slurm_free_job_info_msg(job_ptr);
//More work to do
// exit(0);
}
/*-------------------------------------------------------------------
* quantify_pending_job():
*
* Determine job idleness by comparing lsb_pendreason to certain
* key pending reasons. Idle jobs are defined as:
*
* (a) those that do not have enough processes available
* (b) freshly submitted jobs
*
* Deferred jobs are the inverse.
*---------------------------------------------------------------------*/
int quantify_pending_job(char *reason)
{
const char *idle_string1 = "New job is waiting for scheduling";
const char *idle_string2 = "Not enough processors";
const char *idle_string3 = "Job was suspended";
const char *idle_string4 = "Job\'s requirement for exclusive execution not satisfied";
char *local;
if(strstr(reason,idle_string1) != NULL)
return(0);
else if(strstr(reason,idle_string2) != NULL)
return(1);
else if(strstr(reason,idle_string3) != NULL)
return(2);
else if(strstr(reason,idle_string4) != NULL)
return(1);
else
return(3);
}
/*-------------------------------------
* Parse/Define command line arguments
*-------------------------------------*/
#if 0
void parse_command_line(int argc,char **argv)
{
/* Allowable command line options */
#if 1
struct arg_lit *l = arg_lit0("l", NULL, "long (wide) listing");
struct arg_lit *u = arg_lit0("u", NULL, "display jobs for "
"current user only");
struct arg_lit *all_res = arg_lit0(NULL,"all-reserv",
"show all advanced reservations");
struct arg_lit *help = arg_lit0(NULL,"help","print this help and exit");
struct arg_lit *version = arg_lit0(NULL,"version",
"print version information and exit");
struct arg_end *end = arg_end(20);
void* argtable[] = {l,u,all_res,help,version,end};
const char* progname = "slurm_showq";
int exitcode=0;
int nerrors;
#endif
/* verify the argtable[] entries were allocated sucessfully */
if (arg_nullcheck(argtable) != 0)
{
printf("%s: insufficient memory\n",progname);
exit(1);
}
/* set any command line default values prior to parsing */
/* Parse the command line as defined by argtable[] */
nerrors = arg_parse(argc,argv,argtable);
/* special case: '--help' takes precedence over error reporting */
if (help->count > 0)
{
printf("\nUsage: %s ", progname);
arg_print_syntax(stdout,argtable,"\n");
printf("\nshowq summarizes all running, idle, and pending jobs \n");
printf("along with any advanced reservations "
"in the SLURM batch system.\n\n");
arg_print_glossary(stdout,argtable," %-25s %s\n");
printf("\n");
exit(0);
}
/* special case: '--version' takes precedence error reporting */
if (version->count > 0)
{
printf("\n%s: Version %2.1f\n",progname,VERSION);
printf("Texas Advanced Computing Center, "
"The University of Texas at Austin\n\n");
exit(0);
}
/* If the parser returned any errors then display them and exit */
if (nerrors > 0)
{
arg_print_errors(stdout,end,progname);
printf("Try '%s --help' for more information.\n",progname);
exit(1);
}
/* normal case: take the command line options at face value */
if(l->count > 0)
long_listing = 1;
if(u->count > 0)
user_jobs_only = 1;
if(all_res->count > 0)
show_all_reserv = 1;
return;
}
#endif
char *Slurm_Showq::getusername()
{
char *user = 0;
struct passwd *pw;
pw = getpwuid(getuid());
if (pw)
user = pw->pw_name;
return user;
}
string Slurm_Showq::uid_to_string (uid_t id)
{
string username="nobody";
struct passwd *pwd;
//if( (named_user_jobs_only == true || user_jobs_only == true) || cache_etcpwd_unames == false)
if( cache_etcpwd_unames == false )
{
if( (pwd = getpwuid(id)) == NULL)
printf("Error: unable to ascertain user for uid = %u\n",id);
else
username = pwd->pw_name;
}
else
{
username=uid_uname[(int)id];
if(username.empty())
{
username="nobody";
printf("Error: unable to ascertain user for uid = %u\n",id);
}
}
return(username);
}
void Slurm_Showq::get_etcpwd_unames()
{
string uname,x;
int uid;
//if( named_user_jobs_only == false && user_jobs_only == false && cache_etcpwd_unames == true)
if( cache_etcpwd_unames == true )
{
const char *fileName="/etc/passwd";
ifstream pwdFile;
pwdFile.open(fileName);
string line;
while(getline(pwdFile,line)){
//std::replace(line.begin(), line.end(), ':', ' '); //might be faster
line.replace(line.find(":"), 1, " ");
line.replace(line.find(":"), 1, " ");
line.replace(line.find(":"), 1, " ");
istringstream ss(line);
ss >> uname >> x >> uid;
uid_uname[uid] = uname;
}
pwdFile.close();
//for(const auto& p :uid_uname){ cout << p.first << ' ' << p.second << endl;}
}
return;
}
//-------------------------------------------------------------
// parse_supported_options: Parse/Define command line arguments
//-------------------------------------------------------------
void Slurm_Showq::parse_supported_options(int argc, char *argv[])
{
GetPot cl(argc,argv);
if(cl.search("--version"))
print_version();
if(cl.search(2,"--long","-l"))
long_listing = true;
if(cl.search(2,"--help","-h"))
print_usage();
if(cl.search(2,"-u","--user"))
user_jobs_only = true;
if (cl.search("-U"))
{
named_user_jobs_only=true;
named_user=cl.next("");
}
if (user_jobs_only && named_user_jobs_only)
{
fprintf(stderr,"\n -U and -u are mutually exclusive options. Exiting.\n");
print_usage();
}
}
//-------------------------------------------------------------
// print_usage: show command options