This repository has been archived by the owner on Dec 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommon_sub_fns.sh
866 lines (804 loc) · 24.5 KB
/
common_sub_fns.sh
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
MPIPROCS=1
OMPTHREADS=1
THREADS=1
HELP=0
XTRA_MEM=0
SIZEPERMPI=96
SUBMIT_JOB=1
HOSTNAME=`hostname`
if [ "$HOSTNAME" = "flogin1" -o "$HOSTNAME" = "flogin2" -o "$HOSTNAME" = "fbuild" -o "$HOSTNAME" = "fpbs" -o "$HOSTNAME" = "fbuild2" ]
then
CLUSTER="fission"
CORES_PER_NODE=32
CPU_TYPE="magnycours"
elif [ "$HOSTNAME" = "falcon1" -o "$HOSTNAME" = "falcon2" -o "$HOSTNAME" = "service2" -o "$HOSTNAME" = "falconviz" ]
then
CLUSTER="falcon"
CORES_PER_NODE=24
CPU_TYPE="haswell"
elif [ "$HOSTNAME" = "quark" ]
then
CLUSTER="quark"
CORES_PER_NODE=12
elif [ "$HOSTNAME" = "bechler" ]
then
CLUSTER="bechler"
CORES_PER_NODE=32
CPU_TYPE="sandybridge"
else
echo "Error: Machine $HOSTNAME is not supported."
exit 1
fi
#IOZONE_EXEC=iozone_$CLUSTER
IOZONE_EXEC=iozone
MD_EXEC=mdtest_$CLUSTER
MPI_PER_NODE=$CORES_PER_NODE
function calc_chunk {
if [ $CPU_TYPE == "broadwell" ]
then
CORES_PER_NODE=36
if [ -z $MPI_PER_NODE_SET ]
then
MPI_PER_NODE=$CORES_PER_NODE
fi
fi
if [ $XTRA_MEM -eq 1 ]
then
MPIPROCS=$(($MPIPROCS - 1))
fi
# TOTAL_PROCS=$(($MPIPROCS * $OMPTHREADS))
TOTAL_PROCS=$MPIPROCS
# echo "TOTAL_PROCS = $TOTAL_PROCS"
NNODES=`expr $TOTAL_PROCS / $MPI_PER_NODE`
DIV_BY_CORES_PER_NODE=`expr $TOTAL_PROCS % $CORES_PER_NODE`
MOD_BY_MPI_PER_NODE=`expr $TOTAL_PROCS % $MPI_PER_NODE`
STR1=""
STR2=""
# if [ $DIV_BY_CORES_PER_NODE -ne 0 ]
# then
# STR1="Warning: You have requested $TOTAL_PROCS mpi processes, it would be more efficient to"
# STR2=" request mpi processes in multiples of $CORES_PER_NODE."
## echo "Warning: You have requested $1 mpi processes, it would be more efficient (on Fission) to"
## echo " request mpi processes in multiples of 32."
# fi
if [ $TOTAL_PROCS -le $CORES_PER_NODE -a $MPI_PER_NODE -eq $CORES_PER_NODE ]
then
NNODES=1
RPROCS1=$MPIPROCS
elif [ $MOD_BY_MPI_PER_NODE -eq 0 ]
then
RPROCS1=`expr $MPIPROCS / $NNODES`
else
RPROCS1=$MPI_PER_NODE
TMP2=$(($RPROCS1 * $NNODES))
RPROCS2=`expr $MPIPROCS - $TMP2`
fi
# echo "NNODES = $NNODES RPROCS1 = $RPROCS1 RPROCS2 = $RPROCS2"
# echo "MOD_BY_MPI_PER_NODE = $MOD_BY_MPI_PER_NODE"
}
function check_command_args {
if [ $HELP -ne 1 ]
then
if [ -z "$PBS_JOB_ARRAY_RANGE" -a -z "$PBS_JOB_ARRAY_FILENAME" ]
then
if [ "$EXE_NAME" == "vasp" ]
then
if [ -z "$WALLTIME" ]
then
echo "Error: Make sure you specify the Scheduler Walltime."
usage
exit 1
fi
else
if [ -z "$INPUT" -o -z "$WALLTIME" ]
then
if [ "$EXE_NAME" == "starccm+" ]
then
echo "Error: Make sure you specify the Sim file and PBS Walltime."
else
echo "Error: Make sure you specify the input file and PBS Walltime."
fi
usage
exit 1
fi
fi
else
if [ -z "$PBS_JOB_ARRAY_RANGE" -o -z "$PBS_JOB_ARRAY_FILENAME" ]
then
echo "Error: If you want to use job arrays you need to provide the job_array_range and a job_array_filename"
usage
exit 1
fi
fi
if [ $THREADS -gt $CORES_PER_NODE ]
then
echo " Error: Maximum number of threads per node is $CORES_PER_NODE"
exit 1
fi
fi
if [ -n "$PBS_JOB_ARRAY_RANGE" -a -z "$WALLTIME" ]
then
echo "Error: Walltime not specified on the command line."
usage
exit 1
fi
if [ $OMPTHREADS -gt $CORES_PER_NODE ]
then
echo " Error: You specified $OMPTHREADS threads, you cannot specify more than $CORES_PER_NODE."
exit 1
fi
}
function slurm_check_command_args {
if [ $HELP -ne 1 ]
then
if [ -z "$JOB_ARRAY_RANGE" -a -z "$JOB_ARRAY_FILENAME" ]
then
if [ "$EXE_NAME" == "vasp" ]
then
if [ -z "$WALLTIME" ]
then
echo "Error: Make sure you specify the Scheduler Walltime."
usage
exit 1
fi
else
if [ -z "$INPUT" -o -z "$WALLTIME" ]
then
if [ "$EXE_NAME" == "starccm+" ]
then
echo "Error: Make sure you specify the Sim file and PBS Walltime."
else
echo "Error: Make sure you specify the input file and PBS Walltime."
fi
usage
exit 1
fi
fi
else
if [ -z "$JOB_ARRAY_RANGE" -o -z "$JOB_ARRAY_FILENAME" ]
then
echo "Error: If you want to use job arrays you need to provide the job_array_range and a job_array_filename"
usage
exit 1
fi
fi
if [ $THREADS -gt $CORES_PER_NODE ]
then
echo " Error: Maximum number of threads per node is $CORES_PER_NODE"
exit 1
fi
fi
if [ -n "$JOB_ARRAY_RANGE" -a -z "$WALLTIME" ]
then
echo "Error: Walltime not specified on the command line."
usage
exit 1
fi
if [ $OMPTHREADS -gt $CORES_PER_NODE ]
then
echo " Error: You specified $OMPTHREADS threads, you cannot specify more than $CORES_PER_NODE."
exit 1
fi
}
function set_default_jobname {
if [ -n "$PBS_JOB_ARRAY_RANGE" ]
then
INPUT=job_array
fi
if [ -z "$JOBNAME" ]
then
if [ "$EXE_NAME" == "vasp" ]
then
JOBNAME=$NAME
else
JOBNAME=$INPUT
fi
fi
}
function slurm_set_default_jobname {
if [ -n "$JOB_ARRAY_RANGE" ]
then
INPUT=job_array
fi
if [ -z "$JOBNAME" ]
then
if [ "$EXE_NAME" == "vasp" ]
then
JOBNAME=$NAME
else
JOBNAME=$INPUT
fi
fi
}
function pbs_set_defaults {
echo "#PBS -N $JOBNAME" >> $1
if [ -n "$QUEUE" ]
then
echo "#PBS -q $QUEUE" >> $1
fi
echo "#PBS -l walltime=$WALLTIME" >> $1
echo "#PBS -ko" >> $1
echo "#PBS -j oe" >> $1
if [ -n "$PROJECT" ]
then
echo "#PBS -P $PROJECT" >> $1
fi
}
function slurm_set_defaults {
if [ -n "$JOB_ARRAY_RANGE" ]
then
echo "#SBATCH --job-name=${JOBNAME}"_"%a" >> $1
echo "#SBATCH --output=$JOBNAME.o%A_%a" >> $1
echo "#SBATCH --error=$JOBNAME.o%A_%a" >> $1
else
echo "#SBATCH --job-name=$JOBNAME" >> $1
echo "#SBATCH --output=$JOBNAME.o%A" >> $1
echo "#SBATCH --error=$JOBNAME.o%A" >> $1
fi
if [ -n "$QUEUE" ]
then
echo "#SBATCH --partition=$QUEUE" >> $1
fi
echo "#SBATCH --time=$WALLTIME" >> $1
# if [ -n "$PROJECT" ]
# then
# echo "#PBS -P $PROJECT" >> $1
# fi
}
function pbs_depends_on {
if [ -n "$DEPENDS_ON_JOBID" ]
then
echo "#PBS -W depend=afterany:$DEPENDS_ON_JOBID" >> $1
fi
}
function slurm_depends_on {
if [ -n "$DEPENDS_ON_JOBID" ]
then
echo "#SBATCH --dependency=afterany:$DEPENDS_ON_JOBID" >> $1
fi
}
function pbs_depends_on {
if [ -n "$DEPENDS_ON_JOBID" ]
then
echo "#PBS -W depend=afterany:$DEPENDS_ON_JOBID" >> $1
fi
}
function pbs_jobarray {
if [ -n "$PBS_JOB_ARRAY_RANGE" ]
then
echo "#PBS -r y" >> $1
echo "#PBS -J $PBS_JOB_ARRAY_RANGE" >> $1
fi
}
function slurm_jobarray {
if [ -n "$JOB_ARRAY_RANGE" ]
then
echo "#SBATCH --array $JOB_ARRAY_RANGE" >> $1
fi
}
function pbs_select {
if [ $XTRA_MEM -eq 1 ]
then
if [ -n "$RPROCS2" ]
then
if [ -n "$PBS_MEM" ]
then
echo "#PBS -l select=1:ncpus=$CORES_PER_NODE:cputype=$CPU_TYPE:mem=$PBS_MEM:mpiprocs=1+$NNODES:ncpus=$NCPUS:cputype=$CPU_TYPE:mem=$PBS_MEM:mpiprocs=$RPROCS1+1:ncpus=$NCPUS:mpiprocs=$RPROCS2:cputype=$CPU_TYPE:mem=$PBS_MEM" >> $1
else
echo "#PBS -l select=1:ncpus=$CORES_PER_NODE:cputype=$CPU_TYPE:mpiprocs=1+$NNODES:ncpus=$NCPUS:mpiprocs=$RPROCS1:cputype=$CPU_TYPE+1:ncpus=$NCPUS:mpiprocs=$RPROCS2:cputype=$CPU_TYPE" >> $1
fi
else
if [ -n "$PBS_MEM" ]
then
echo "#PBS -l select=1:ncpus=$CORES_PER_NODE:cputype=$CPU_TYPE:mem=$PBS_MEM:mpiprocs=1+$NNODES:ncpus=$NCPUS:mpiprocs=$RPROCS1:cputype=$CPU_TYPE:mem=$PBS_MEM" >> $1
else
echo "#PBS -l select=1:ncpus=$CORES_PER_NODE:cputype=$CPU_TYPE:mpiprocs=1+$NNODES:ncpus=$NCPUS:mpiprocs=$RPROCS1:cputype=$CPU_TYPE" >> $1
fi
fi
else
if [ -n "$RPROCS2" ]
then
if [ -n "$PBS_MEM" ]
then
echo "#PBS -l select=1:ncpus=$NCPUS:mem=$PBS_MEM:mpiprocs=$RPROCS2:cputype=$CPU_TYPE+$NNODES:ncpus=$NCPUS:mpiprocs=$RPROCS1:cputype=$CPU_TYPE:mem=$PBS_MEM" >> $1
else
echo "#PBS -l select=1:ncpus=$NCPUS:mpiprocs=$RPROCS2:cputype=$CPU_TYPE+$NNODES:ncpus=$NCPUS:mpiprocs=$RPROCS1:cputype=$CPU_TYPE" >> $1
fi
else
if [ -n "$PBS_MEM" ]
then
echo "#PBS -l select=$NNODES:ncpus=$NCPUS:mpiprocs=$RPROCS1:cputype=$CPU_TYPE:mem=$PBS_MEM" >> $1
else
echo "#PBS -l select=$NNODES:ncpus=$NCPUS:mpiprocs=$RPROCS1:cputype=$CPU_TYPE" >> $1
fi
fi
fi
}
function slurm_tasks {
if [ -n "$MEM_PER_PROCESS" ]
then
echo "#SBATCH --ntasks=$MPIPROCS" >> $1
echo "#SBATCH --ntasks-per-node=$MPI_PER_NODE" >> $1
echo "#SBATCH --mem-per-cpu=$MEM_PER_PROCESS" >> $1
else
echo "#SBATCH --ntasks=$MPIPROCS" >> $1
echo "#SBATCH --ntasks-per-node=$MPI_PER_NODE" >> $1
fi
}
function load_modules {
echo "source /etc/profile.d/modules.sh" >> $1
if [ -n "$EXTRA_MODULE_NAME1" ]
then
echo "module load $EXTRA_MODULE_NAME1" >> $1
fi
if [ -n "$EXTRA_MODULE_NAME2" ]
then
echo "module load $EXTRA_MODULE_NAME2" >> $1
fi
if [ -n "$DEBUG_JOB" ]
then
echo "module load use.projects utils" >> $1
fi
echo "module load $MODULE_NAME" >> $1
if [ "$EXE_NAME" == "abaqus" ]
then
if [ -n "$GCC_MODULE_NAME" ]
then
echo "module load $GCC_MODULE_NAME" >> $1
fi
echo "module load $COMPILER_MODULE_NAME" >> $1
fi
}
#function create_slurm_nodefile {
# python /home/garvct/my_sw_development/pbs_job_submit/slurm_nodefile.py $1
#}
function slurm_create_nodefile {
echo "export SLURM_NODEFILE=/tmp/slurm_\$SLURM_JOBID" >> $1
echo "scontrol show hostname \$SLURM_JOB_NODELIST >& \$SLURM_NODEFILE" >> $1
}
function debug_job {
if [ -n "$DEBUG_JOB" ]
then
echo "cat \$PBS_NODEFILE | uniq > mpd.hosts_\$\$" >> $1
echo "checkBasicStatus.py -f mpd.hosts_\$\$" >> $1
# echo "check_node_mem_pbs.sh 180 &" >> $1
fi
# Not the best place to put this logic, but didnot want to break existing sub_app scripts.
echo "JOB_NUM=\${PBS_JOBID%\.*}" >> $1
if [ -z "$PBS_JOB_ARRAY_RANGE" ]
then
echo "if [ \$PBS_O_WORKDIR != \$HOME ]" >> $1
echo "then" >> $1
echo "ln -s \$HOME/\$PBS_JOBNAME.o\$JOB_NUM \$PBS_JOBNAME.o\$JOB_NUM" >> $1
echo "fi" >> $1
fi
}
function slurm_debug_job {
if [ -n "$DEBUG_JOB" ]
then
echo "cat \$SLURM_NODEFILE | uniq > mpd.hosts_\$\$" >> $1
echo "checkBasicStatus.py -f mpd.hosts_\$\$" >> $1
# echo "check_node_mem_pbs.sh 180 &" >> $1
fi
echo "JOB_NUM=\${SLURM_JOB_ID%\.*}" >> $1
}
function setup_run_in_scratch {
if [ -n "$SCRATCH_TYPE" ]
then
echo "export TMPDIR=$SCRATCH_BASE_DIR/\$\$" >> $1
if [ $SCRATCH_TYPE != "scratch" ]
then
echo "for host in \`uniq \$PBS_NODEFILE\`" >> $1
echo "do" >> $1
echo "ssh \$host mkdir $SCRATCH_BASE_DIR/\$\$" >> $1
echo "done" >> $1
echo "hostfile=(\$(cat \$PBS_NODEFILE))" >> $1
echo "echo \"Job run on \${hostfile[0]} at $SCRATCH_BASE_DIR/\$\$\"" >> $1
else
echo "mkdir $SCRATCH_BASE_DIR/\$\$" >> $1
if [ -z "$PBS_JOB_ARRAY_RANGE" ]
then
echo "ln -s $SCRATCH_BASE_DIR/\$\$" >> $1
fi
fi
if [ -z "$PBS_JOB_ARRAY_RANGE" ]
then
if [ "$EXE_NAME" == "vasp" ]
then
echo "rsync --exclude INCAR --exclude POTCAR --exclude POSCAR --exclude KPOINTS --exclude $JOBNAME.pbs . $SCRATCH_BASE_DIR/\$\$" >> $1
else
echo "rsync --exclude $2 --exclude $JOBNAME.pbs . $SCRATCH_BASE_DIR/\$\$" >> $1
fi
echo "cd $SCRATCH_BASE_DIR/\$\$" >> $1
if [ "$EXE_NAME" == "vasp" ]
then
echo "ln -s \$PBS_O_WORKDIR/INCAR && ln -s \$PBS_O_WORKDIR/KPOINTS && ln -s \$PBS_O_WORKDIR/POSCAR && ln -s \$PBS_O_WORKDIR/POTCAR" >> $1
else
echo "ln -s \$PBS_O_WORKDIR/$2" >> $1
fi
fi
else
echo "export TMPDIR=/tmp" >> $1
fi
}
function slurm_setup_run_in_scratch {
if [ -n "$SCRATCH_TYPE" ]
then
echo "export TMPDIR=$SCRATCH_BASE_DIR/\$\$" >> $1
if [ $SCRATCH_TYPE != "scratch" ]
then
echo "for host in \`uniq \$SLURM_NODEFILE\`" >> $1
echo "do" >> $1
echo "ssh \$host mkdir $SCRATCH_BASE_DIR/\$\$" >> $1
echo "done" >> $1
echo "hostfile=(\$(cat \$SLURM_NODEFILE))" >> $1
echo "echo \"Job run on \${hostfile[0]} at $SCRATCH_BASE_DIR/\$\$\"" >> $1
else
echo "mkdir $SCRATCH_BASE_DIR/\$\$" >> $1
if [ -z "$JOB_ARRAY_RANGE" ]
then
echo "ln -s $SCRATCH_BASE_DIR/\$\$" >> $1
fi
fi
if [ -z "$JOB_ARRAY_RANGE" ]
then
if [ "$EXE_NAME" == "vasp" ]
then
echo "rsync --exclude INCAR --exclude POTCAR --exclude POSCAR --exclude KPOINTS --exclude $JOBNAME.sbatch . $SCRATCH_BASE_DIR/\$\$" >> $1
else
echo "rsync --exclude $2 --exclude $JOBNAME.sbatch . $SCRATCH_BASE_DIR/\$\$" >> $1
fi
echo "cd $SCRATCH_BASE_DIR/\$\$" >> $1
if [ "$EXE_NAME" == "vasp" ]
then
echo "ln -s \$SLURM_SUBMIT_DIR/INCAR && ln -s \$SLURM_SUBMIT_DIR/KPOINTS && ln -s \$SLURM_SUBMIT_DIR/POSCAR && ln -s \$SLURM_SUBMIT_DIR/POTCAR" >> $1
else
echo "ln -s \$SLURM_SUBMIT_DIR/$2" >> $1
fi
fi
else
echo "export TMPDIR=/tmp" >> $1
fi
}
function setup_jobarray {
if [ -n "$PBS_JOB_ARRAY_RANGE" ]
then
echo "OLDIFS=\$IFS" >> $1
echo "IFS=\$'\n'" >> $1
echo "job_array_file=(\$(cat $PBS_JOB_ARRAY_FILENAME))" >> $1
echo "IFS=\$OLDIFS" >> $1
echo "job_array_file_line=( \${job_array_file[\$PBS_ARRAY_INDEX]} )" >> $1
if [ "$EXE_NAME" == "vasp" ]
then
echo "dir_path=\$job_array_file_line" >> $1
else
echo "dir_path=\$(dirname \$job_array_file_line)" >> $1
echo "input_name=\$(basename \$job_array_file_line)" >> $1
fi
if [ "$EXE_NAME" == "abaqus" ]
then
echo "if [[ \$input_name =~ .*\.inp ]]" >> $1
echo "then" >> $1
echo " input_name=\$input_name" >> $1
echo "else" >> $1
echo " input_name=\$input_name\".inp\"" >> $1
echo "fi" >> $1
fi
if [ "$EXE_NAME" == "starccm+" ]
then
echo "if [[ \$input_name =~ .*\.sim ]]" >> $1
echo "then" >> $1
echo " input_name=\$input_name" >> $1
echo "else" >> $1
echo " input_name=\$input_name\".sim\"" >> $1
echo "fi" >> $1
fi
echo "cd \$dir_path" >> $1
if [ "$NAME" == "mc21" ]
then
echo "ln -sf $ND_LIBRARY_FULLPATH ND_LIBRARY" >> $1
fi
if [ -n "$SCRATCH_TYPE" ]
then
if [ "$EXE_NAME" == "vasp" ]
then
echo "rsync --exclude INCAR --exclude POTCAR --exclude POSCAR --exclude KPOINTS --exclude $JOBNAME.pbs . $SCRATCH_BASE_DIR/\$\$" >> $1
else
echo "rsync --exclude \$input_name --exclude $JOBNAME.pbs . $SCRATCH_BASE_DIR/\$\$" >> $1
fi
if [ $SCRATCH_TYPE == "scratch" ]
then
echo "ln -s $SCRATCH_BASE_DIR/\$\$" >> $1
fi
echo "cd $SCRATCH_BASE_DIR/\$\$" >> $1
if [ "$EXE_NAME" == "vasp" ]
then
echo "ln -s \$dir_path/INCAR" >> $1
echo "ln -s \$dir_path/KPOINTS" >> $1
echo "ln -s \$dir_path/POSCAR" >> $1
echo "ln -s \$dir_path/POTCAR" >> $1
else
echo "ln -s \$dir_path/\$input_name" >> $1
fi
fi
echo "JA_JOB_NUM=\${JOB_NUM%[*}" >> $1
echo "ln -s $HOME/\$PBS_JOBNAME.o\$JA_JOB_NUM.\$PBS_ARRAY_INDEX \$dir_path/\$PBS_JOBNAME.o\$JA_JOB_NUM.\$PBS_ARRAY_INDEX" >> $1
fi
}
function slurm_setup_jobarray {
if [ -n "$JOB_ARRAY_RANGE" ]
then
echo "OLDIFS=\$IFS" >> $1
echo "IFS=\$'\n'" >> $1
echo "job_array_file=(\$(cat $JOB_ARRAY_FILENAME))" >> $1
echo "IFS=\$OLDIFS" >> $1
echo "job_array_file_line=( \${job_array_file[\$SLURM_ARRAY_TASK_ID]} )" >> $1
if [ "$EXE_NAME" == "vasp" ]
then
echo "dir_path=\$job_array_file_line" >> $1
else
echo "dir_path=\$(dirname \$job_array_file_line)" >> $1
echo "input_name=\$(basename \$job_array_file_line)" >> $1
fi
if [ "$EXE_NAME" == "abaqus" ]
then
echo "if [[ \$input_name =~ .*\.inp ]]" >> $1
echo "then" >> $1
echo " input_name=\$input_name" >> $1
echo "else" >> $1
echo " input_name=\$input_name\".inp\"" >> $1
echo "fi" >> $1
fi
if [ "$EXE_NAME" == "starccm+" ]
then
echo "if [[ \$input_name =~ .*\.sim ]]" >> $1
echo "then" >> $1
echo " input_name=\$input_name" >> $1
echo "else" >> $1
echo " input_name=\$input_name\".sim\"" >> $1
echo "fi" >> $1
fi
echo "cd \$dir_path" >> $1
if [ "$NAME" == "mc21" ]
then
echo "ln -sf $ND_LIBRARY_FULLPATH ND_LIBRARY" >> $1
fi
if [ -n "$SCRATCH_TYPE" ]
then
if [ "$EXE_NAME" == "vasp" ]
then
echo "rsync --exclude INCAR --exclude POTCAR --exclude POSCAR --exclude KPOINTS --exclude $JOBNAME.sbatch . $SCRATCH_BASE_DIR/\$\$" >> $1
else
echo "rsync --exclude \$input_name --exclude $JOBNAME.sbatch . $SCRATCH_BASE_DIR/\$\$" >> $1
fi
if [ $SCRATCH_TYPE == "scratch" ]
then
echo "ln -s $SCRATCH_BASE_DIR/\$\$" >> $1
fi
echo "cd $SCRATCH_BASE_DIR/\$\$" >> $1
if [ "$EXE_NAME" == "vasp" ]
then
echo "ln -s \$dir_path/INCAR" >> $1
echo "ln -s \$dir_path/KPOINTS" >> $1
echo "ln -s \$dir_path/POSCAR" >> $1
echo "ln -s \$dir_path/POTCAR" >> $1
else
echo "ln -s \$dir_path/\$input_name" >> $1
fi
fi
# echo "JA_JOB_NUM=\${JOB_NUM%[*}" >> $1
# echo "ln -s $HOME/\$PBS_JOBNAME.o\$JA_JOB_NUM.\$PBS_ARRAY_INDEX \$dir_path/\$PBS_JOBNAME.o\$JA_JOB_NUM.\$PBS_ARRAY_INDEX" >> $1
fi
}
function finish_jobarray_and_scratch {
if [ -n "$PBS_JOB_ARRAY_RANGE" ]
then
if [ -n "$SCRATCH_TYPE" ]
then
if [ "$EXE_NAME" == "vasp" ]
then
echo "rsync -a --exclude INCAR --exclude POTCAR --exclude POSCAR --exclude KPOINTS . \$dir_path" >> $1
else
echo "rsync -a --exclude \$input_name . \$dir_path" >> $1
fi
fi
echo "rm \$dir_path/\$PBS_JOBNAME.o\$JA_JOB_NUM.\$PBS_ARRAY_INDEX" >> $1
echo "mv \$HOME/\$PBS_JOBNAME.o\$JA_JOB_NUM.\$PBS_ARRAY_INDEX \$dir_path/\$PBS_JOBNAME.o\$JA_JOB_NUM.\$PBS_ARRAY_INDEX" >> $1
else
if [ -n "$SCRATCH_TYPE" ]
then
if [ "$EXE_NAME" == "vasp" ]
then
echo "rsync -a --exclude INCAR --exclude POTCAR --exclude POSCAR --exclude KPOINTS . \$PBS_O_WORKDIR" >> $1
else
echo "rsync -a --exclude $INPUT . \$PBS_O_WORKDIR" >> $1
fi
fi
echo "#" >> $1
echo "if [ \$PBS_O_WORKDIR != \$HOME ]" >> $1
echo "then" >> $1
echo "rm \$PBS_O_WORKDIR/\$PBS_JOBNAME.o\$JOB_NUM" >> $1
echo "mv \$HOME/\$PBS_JOBNAME.o\$JOB_NUM \$PBS_O_WORKDIR/\$PBS_JOBNAME.o\$JOB_NUM" >> $1
echo "fi" >> $1
fi
if [ -n "$SCRATCH_TYPE" ]
then
if [ $SCRATCH_TYPE != "scratch" ]
then
echo "for host in \`uniq \$PBS_NODEFILE\`" >> $1
echo "do" >> $1
echo "ssh \$host rm -R $SCRATCH_BASE_DIR/\$\$" >> $1
echo "done" >> $1
else
echo "rm -R $SCRATCH_BASE_DIR/\$\$" >> $1
if [ -n "$PBS_JOB_ARRAY_RANGE" ]
then
echo "rm \$dir_path/\$\$" >> $1
else
echo "rm \$PBS_O_WORKDIR/\$\$" >> $1
fi
fi
fi
}
function slurm_finish_jobarray_and_scratch {
if [ -n "$JOB_ARRAY_RANGE" ]
then
if [ -n "$SCRATCH_TYPE" ]
then
if [ "$EXE_NAME" == "vasp" ]
then
echo "rsync -a --exclude INCAR --exclude POTCAR --exclude POSCAR --exclude KPOINTS . \$dir_path" >> $1
else
echo "rsync -a --exclude \$input_name . \$dir_path" >> $1
fi
fi
else
if [ -n "$SCRATCH_TYPE" ]
then
if [ "$EXE_NAME" == "vasp" ]
then
echo "rsync -a --exclude INCAR --exclude POTCAR --exclude POSCAR --exclude KPOINTS . \$SLURM_SUBMIT_DIR" >> $1
else
echo "rsync -a --exclude $INPUT . \$SLURM_SUBMIT_DIR" >> $1
fi
fi
echo "#" >> $1
# echo "if [ \$PBS_O_WORKDIR != \$HOME ]" >> $1
# echo "then" >> $1
# echo "rm \$PBS_O_WORKDIR/\$PBS_JOBNAME.o\$JOB_NUM" >> $1
# echo "mv \$HOME/\$PBS_JOBNAME.o\$JOB_NUM \$PBS_O_WORKDIR/\$PBS_JOBNAME.o\$JOB_NUM" >> $1
# echo "fi" >> $1
fi
if [ -n "$SCRATCH_TYPE" ]
then
if [ $SCRATCH_TYPE != "scratch" ]
then
echo "for host in \`uniq \$SLURM_NODEFILE\`" >> $1
echo "do" >> $1
echo "ssh \$host rm -R $SCRATCH_BASE_DIR/\$\$" >> $1
echo "done" >> $1
else
echo "rm -R $SCRATCH_BASE_DIR/\$\$" >> $1
if [ -n "$JOB_ARRAY_RANGE" ]
then
echo "rm \$dir_path/\$\$" >> $1
else
echo "rm \$SLURM_SUBMIT_DIR/\$\$" >> $1
fi
fi
fi
}
function calc_chunk_new {
if [ -z $MPI_PER_NODE_SET ]
then
if [ $XTRA_MEM -eq 1 ]
then
MPIPROCS=$(($MPIPROCS - 1))
fi
NNODES=$MPIPROCS
RPROCS1=1
NCPUS=1
else
if [ $CPU_TYPE == "broadwell" ]
then
CORES_PER_NODE=36
if [ -z $MPI_PER_NODE_SET ]
then
MPI_PER_NODE=$CORES_PER_NODE
fi
fi
if [ $XTRA_MEM -eq 1 ]
then
MPIPROCS=$(($MPIPROCS - 1))
fi
# TOTAL_PROCS=$(($MPIPROCS * $OMPTHREADS))
TOTAL_PROCS=$MPIPROCS
# echo "TOTAL_PROCS = $TOTAL_PROCS"
NNODES=`expr $TOTAL_PROCS / $MPI_PER_NODE`
DIV_BY_CORES_PER_NODE=`expr $TOTAL_PROCS % $CORES_PER_NODE`
MOD_BY_MPI_PER_NODE=`expr $TOTAL_PROCS % $MPI_PER_NODE`
STR1=""
STR2=""
# if [ $DIV_BY_CORES_PER_NODE -ne 0 ]
# then
# STR1="Warning: You have requested $TOTAL_PROCS mpi processes, it would be more efficient to"
# STR2=" request mpi processes in multiples of $CORES_PER_NODE."
## echo "Warning: You have requested $1 mpi processes, it would be more efficient (on Fission) to"
## echo " request mpi processes in multiples of 32."
# fi
if [ $TOTAL_PROCS -le $CORES_PER_NODE -a $MPI_PER_NODE -eq $CORES_PER_NODE ]
then
NNODES=1
RPROCS1=$MPIPROCS
elif [ $MOD_BY_MPI_PER_NODE -eq 0 ]
then
RPROCS1=`expr $MPIPROCS / $NNODES`
else
RPROCS1=$MPI_PER_NODE
TMP2=$(($RPROCS1 * $NNODES))
RPROCS2=`expr $MPIPROCS - $TMP2`
fi
NCPUS=$CORES_PER_NODE
fi
# echo "NNODES = $NNODES RPROCS1 = $RPROCS1 RPROCS2 = $RPROCS2"
# echo "MOD_BY_MPI_PER_NODE = $MOD_BY_MPI_PER_NODE"
}
function get_ramdisk_size {
if [ $CLUSTER == "falcon" ]
then
RAMDISK_SIZE=100
elif [ $CLUSTER == "fission" ]
then
RAMDISK_SIZE=48
elif [ $CLUSTER == "bechler" ]
then
RAMDISK_SIZE=12
fi
}
function get_localdisk_size {
if [ $CLUSTER == "bechler" ]
then
LOCALDISK_SIZE=250
elif [ $CLUSTER == "quark" ]
then
LOCALDISK_SIZE=100
else
echo "Error: localdisk not available on $CLUSTER"
exit 1
fi
}
function get_scratch_dir {
if [ $1 == "scratch" ]
then
SCRATCH_BASE_DIR="/scratch/$LOGNAME"
elif [ $1 == "ramdisk" ]
then
if [ $CLUSTER == "bechler" ]
then
SCRATCH_BASE_DIR="/dev/shm"
else
SCRATCH_BASE_DIR="/tmp"
fi
get_ramdisk_size
echo
echo "Warning: You have requested to run your job in ramdisk."
echo "Warning: $CLUSTER has $RAMDISK_SIZE GB of ramdisk space available on each Compute Node."
echo "Warning: Make sure your job (temporary files, resulting/output files etc) can fit in this space or else the node will go down and your job will crash."
echo
elif [ $1 == "localdisk" ]
then
if [ $CLUSTER == "bechler" ]
then
SCRATCH_BASE_DIR="/tmp"
else
echo "Error: localdisk not available on $CLUSTER"
exit 1
fi
get_localdisk_size
echo
echo "Warning: You have requested to run your job in localdisk."
echo "Warning: $CLUSTER has $LOCALDISK_SIZE GB of ramdisk space available on each Compute Node."
echo "Warning: Make sure your job (temporary files, resulting/output files etc) can fit in this space or else the node may go down and your job will crash."
echo
fi
}