-
Notifications
You must be signed in to change notification settings - Fork 1
/
regtest.pl
executable file
·3669 lines (3125 loc) · 166 KB
/
regtest.pl
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
#!/usr/bin/perl -w
# Author : Xin Zhang, MMM/NCAR, 8/17/2009
# Updates : March 2013, adapted for Loblolly (PC) and Yellowstone (Mike Kavulich)
# August 2013, added 4DVAR test capability (Mike Kavulich)
# December 2013, added parallel/batch build capability (Mike Kavulich)
# May 2014, added new platform (Mac), improved summary upload, added OBSPROC, 4DVAR, and VARBC test capabilities
# June 2014, added FGAT test capability
# August 2014, added GENBE test capability (for yellowstone)
# January 2015, added GENBE test capability for PC and Mac, update for CV7 tests, several other updates and fixes
# March 2015, added CLOUD_CV compilation option, adding 4DVAR GENBE capability, updates to web summary upload
# April 2015, different compiler versions now have different BASELINE files, generalize yellowstone job scripts
# May 2015, added CYCLING job capability for yellowstone, overhauled job hash structure for better summary reports
# September 2015, added CYCLING capability and track sub-job info for local machines
# November 2015, added HYBRID job capability
# December 2015, added HDF5 and NETCDF4 capabilities
# January 2016, added 4DVAR serial test capability
# February 2016, Added HYBRID capabilities for local machines, enabled sm tests, cleaned up library link system
# June 2016, Added git/Github functionality
# November 2016, Added 4DENVAR as test type (existing HYBRID types are now called 3DENVAR)
use strict;
use Term::ANSIColor;
use Time::HiRes qw(sleep gettimeofday);
use Time::localtime;
use Sys::Hostname;
use File::Copy;
use File::Path;
use File::Basename;
use File::Compare;
use IPC::Open2;
use Net::FTP;
use Getopt::Long;
use Data::Dumper;
use Scalar::Util qw(looks_like_number);
# Start time:
my $Start_time;
my $tm = localtime;
$Start_time=sprintf "Begin : %02d:%02d:%02d-%04d/%02d/%02d\n",
$tm->hour, $tm->min, $tm->sec, $tm->year+1900, $tm->mon+1, $tm->mday;
# Where am I?
my $MainDir = `pwd`; chomp($MainDir);
my $Upload_defined;
my $Compiler_defined;
my $CCompiler_defined = '';
my $Source_defined;
my $Exec_defined;
my $Debug_defined;
my $Parallel_compile_num = 4;
my $Revision_defined = 'HEAD'; # Revision number specified from command line
my $Revision; # Revision number from code
my $Revision_date; # Date of revision if under version control
my $Version; # Version number from tools/version_decl
my $Fork = ""; # Fork; used for git repositories only
my $Branch = ""; # Branch; used for git repositories only
my $WRFPLUS_Revision = 'NONE'; # WRFPLUS Revision number from code
my $Testfile_defined;
my $CLOUDCV_defined;
my $NETCDF4_defined;
my $REPO_defined;
my $REPO_type;
my $RTTOV_dir;
my $test_list_string = '';
my $use_HDF5 = "yes";
my $use_RTTOV = "yes";
my $libdir = "$MainDir/libs";
my @valid_options = ("compiler","cc","source","revision","upload","exec","debug","j","cloudcv","netcdf4","hdf5","rttov","testfile","repo","tests","libs","branch","fork");
#This little bit makes sure the input arguments are formatted correctly
foreach my $arg ( @ARGV ) {
my $first_two = substr($arg, 0, 2);
unless ($first_two eq "--") {
print "\n Unknown option: $arg \n";
&print_help_and_die;
}
#Make sure option is valid
my $valid = 0;
foreach (@valid_options) {
if ($arg =~ "$_") {$valid = 1};
}
if ($valid == 0) {
$arg =~ s/=.*//;
print "\n unknown option: $arg \n";
&print_help_and_die;
}
&print_help_and_die unless ($arg =~ "="); #All options need an equals sign
}
GetOptions( "compiler=s" => \$Compiler_defined,
"cc:s" => \$CCompiler_defined,
"source:s" => \$Source_defined,
"revision:s" => \$Revision_defined,
"upload:s" => \$Upload_defined,
"exec:s" => \$Exec_defined,
"debug:s" => \$Debug_defined,
"j:s" => \$Parallel_compile_num,
"cloudcv:s" => \$CLOUDCV_defined,
"netcdf4:s" => \$NETCDF4_defined,
"hdf5:s" => \$use_HDF5,
"rttov:s" => \$use_RTTOV,
"testfile:s" => \$Testfile_defined,
"repo:s" => \$REPO_defined,
"fork:s" => \$Fork,
"branch:s" => \$Branch,
"tests:s" => \$test_list_string,
"libs:s" => \$libdir ) or &print_help_and_die;
unless ( defined $Compiler_defined ) {
print "\nA compiler must be specified!\n\nAborting the script with dignity.\n";
&print_help_and_die;
}
sub print_help_and_die {
print "\nUsage : regtest.pl --compiler=COMPILER --cc=C_COMPILER --source=SOURCE_CODE.tar --revision=NNNN --upload=[no]/yes\n";
print " --j=NUM_PROCS --exec=[no]/yes --debug=[no]/yes/super --testfile=testdata.txt \n";
print " --netcdf4=[no]/yes --hdf5=no/[yes] --rttov=no/[yes] --cloudcv=[no]/yes\n";
print " --repo=git\@github.com:wrf-model/WRF --fork=github_username --branch=branchname\n";
print " --tests='testname1 testname2' --libs=`pwd`/libs\n\n";
print " compiler: [REQUIRED] Compiler name (supported options: ifort, gfortran, xlf, pgf90, g95)\n";
print " cc: C Compiler name (supported options: icc, gcc, xlf, pgcc, g95)\n";
print " source: Specify location of source code in one of 3 formats:\n";
print " - If a path is specified, script will assume that path contains the WRFDA source code\n";
print " - If a .tar or .gz file is specified, that archive should contain a directory named 'WRFDA'\n";
print " - If 'REPO' is specified, script will look for code from a remote repository; see 'repo' option\n";
print " revision: Specify code revision to retrieve (only works when '--source=REPO' specified)\n";
print " Use any number to specify that revision number; specify 'HEAD' to use the latest revision\n";
print " upload: Uploads summary to web (default is 'yes' iff source==REPO and revision==HEAD)\n";
print " j: Number of processors to use in parallel compile (default 4, use 1 for serial compilation)\n";
print " exec: Execute only; skips compile, utilizes existing executables\n";
print " debug: 'yes' compiles with minimal optimization; 'super' compiles with debugging options as well\n";
print " cloudcv: Compile for CLOUD_CV options\n";
print " netcdf4: Compile for NETCDF4 options\n";
print " hdf5: Compile for HDF5 options (note that the default value is 'yes')\n";
print " rttov: Compile for RTTOV options (note that the default value is 'yes')\n";
print " testfile: Name of test data file (default: testdata.txt)\n";
print " repo: Location of code repository\n";
print " fork: (git only) Overwrites default repository 'git\@github.com:wrf-model/WRF' to 'git\@github.com:fork/WRF'\n";
print " branch: (git only) branch of repository to use\n";
print " tests: Test names to run (prunes test list taken from testfile; test specs must exist there!)\n";
print " libs: Specify where the necessary libraries are located\n";
die "\n";
}
my $Exec;
if (defined $Exec_defined && $Exec_defined ne 'no') {
$Exec = 1;
unless (defined $Source_defined) {$Source_defined = "Existing executable"};
} else {
$Exec = 0;
}
my $Debug;
if (defined $Debug_defined && $Debug_defined eq 'super') {
$Debug = 2;
} elsif (defined $Debug_defined && $Debug_defined eq 'yes') {
$Debug = 1;
} elsif ( !(defined $Debug_defined) || $Debug_defined eq 'no') {
$Debug = 0;
} else {
die "Invalid debug option specified ('$Debug_defined'); valid options are 'no', 'yes', or 'super'";
}
my $Testfile;
if (defined $Testfile_defined) {
$Testfile = $Testfile_defined;
} else {
if ($Debug > 0) {
print "\nDebug options specified: reading 'testdata.txt.debug'\nSpecify '--testfile=' on command line to override this test file name\n\n";
$Testfile = "testdata.txt.debug";
} else {
$Testfile = "testdata.txt";
}
}
if ( $Parallel_compile_num > 16 ) {die "Can not parallel compile using more than 16 processors; set j<=16\n"};
# Who is running the test?
my $Tester = getlogin();
# Local variables
my ($Arch, $Machine, $Name, $Compiler, $CCompiler, $Project, $Source, $Queue, $Database, $Baseline, $missvars);
my $Compile_queue = 'caldera';
my @compile_job_list;
my @Message;
my $Clear = `clear`;
my $diffwrfdir = "";
my @gtsfiles;
my @childs;
my @exefiles;
my @Compiletypes;
my %Experiments ;
my $cmd='';
# Sample %Experiments Structure: #####################
#
# %Experiments (
# cv3_guo => \%record (
# index=> 1
# cpu_mpi=> 32
# cpu_openmp=> 8
# status=>"open"
# test_type=>"3DVAR"
# paropt => {
# serial => {
# currjob => 89123
# currjobnum => 1
# currjobname => "OBSPROC"
# status => "running"
# starttime => 8912312131.2
# endtime => 8912314560.2
# walltime => 17 #sum of subjob walltimes
# result => "--"
# job => {
# 1 => {
# jobid => 89123
# jobname => "OBSPROC"
# status => "done"
# walltime => 17
# }
# }
# 2 => {
# jobid => 89124
# jobname => "GENBE"
# status => "running"
# walltime => 0
# }
# }
# 3 => {
# jobid => 89125
# jobname => "3DVAR"
# status => "pending"
# walltime => 0
# }
# }
# }
# smpar => {
# currjob => 0
# status => "pending"
# starttime => 8912312131.2
# endtime => 8912314560.2
# walltime => 0
# result => "pending"
# }
# }
# )
# t44_liuz => \%record (
# index=> 3
# cpu_mpi=> 16
# cpu_openmp=> 4
# status=>"open"
# test_type=>"3DVAR"
# paropt => {
# serial => {
# currjob => 89123
# status => "done"
# starttime => 8912312131.2
# endtime => 8912314560.2
# walltime => 2529.0
# result => "diff"
# }
# }
# )
# )
#########################################################
my %Compile_options;
my %Compile_options_4dvar;
my $count; #For counting the number of compile options found
my %compile_job_array;
my $go_on=''; #For breaking input loops
# What's my name?
my $ThisGuy = `whoami`; chomp($ThisGuy);
# What's my hostname, system, and machine?
my $Host = hostname();
my $System = `uname -s`; chomp($System);
my $Local_machine = `uname -m`; chomp($Local_machine);
my $Machine_name = `uname -n`; chomp($Machine_name);
if ($Machine_name =~ /yslogin\d/) {$Machine_name = 'yellowstone'};
if ($Machine_name =~ /bacon\d/) {$Machine_name = 'bacon'};
if ( $Machine_name =~ /vpn\d/ ) {
print " Your machine appears to be connected to VPN so we can't determine what machine you are using\n please enter your machine name (the output of the command `uname -n` when not connected to VPN) below:\a\n";
while ($go_on eq "") {
$go_on = <STDIN>;
chop($go_on);
if ($go_on eq "") {
print "Please enter the name of your machine:\n";
} else {
$Machine_name = $go_on;
}
}
}
my @splitted = split(/\./,$Machine_name);
$Machine_name = $splitted[0];
#Sort out the compiler name and version differences
my %convert_compiler = (
gfortran => "gfortran",
gnu => "gfortran",
pgf90 => "pgf90",
pgi => "pgf90",
intel => "ifort",
ifort => "ifort",
);
my %convert_module = (
gfortran => "gnu",
gnu => "gnu",
pgf90 => "pgi",
pgi => "pgi",
intel => "intel",
ifort => "intel",
);
my $Compiler_defined_conv .= $convert_compiler{$Compiler_defined};
my $module_loaded .= $convert_module{$Compiler_defined};
printf "NOTE: You specified '$Compiler_defined' as your compiler.\n Interpreting this as '$Compiler_defined_conv'.\n" unless ( $Compiler_defined eq $Compiler_defined_conv );
$Compiler_defined = $Compiler_defined_conv;
# Assign a C compiler
if ($CCompiler_defined eq '') { #Only assign a C compiler if it was not specified on the command line
if ($Compiler_defined eq "gfortran") {
# if ($Arch eq "Darwin") {
# $CCompiler = "clang";
# } else {
$CCompiler = "gcc";
# }
} elsif ($Compiler_defined eq "pgf90") {
$CCompiler = "pgcc";
} elsif ($Compiler_defined eq "ifort") {
$CCompiler = "icc";
} else {
print "\n ERROR ASSIGNING C COMPILER\n";
&print_help_and_die;
}
}
my $Compiler_version = "";
if (defined $ENV{'COMPILER_VERSION'} ) {
$Compiler_version = $ENV{COMPILER_VERSION}
}
print "Will use libraries in $libdir\n";
# Parse the task table:
open(DATA, "<$Testfile") or die "Couldn't open test file $Testfile, see README for more info $!";
while (<DATA>) {
last if ( /^####/ && (keys %Experiments) > 0 );
next if /^#/;
if ( /^(\D)/ ) {
($Arch, $Machine, $Name, $Compiler, $Project, $Queue, $Database, $Baseline, $Source) =
split /\s+/,$_;
}
if ( /^(\d)+/ && ($System =~ /$Arch/i) ) {
if ( ($Local_machine =~ /$Machine/i) ) {
if ( ($Compiler =~ /$Compiler_defined/i) ) {
if ( ($Name =~ /$Machine_name/i) ) {
$_=~ m/(\d+) \s+ (\S+) \s+ (\S+) \s+ (\S+) \s+ (\S+) \s+ (\S+)/x;
my @tasks = split /\|/, $6;
my %task_records;
$task_records{$_} = {} for @tasks;
my %record = (
index => $1,
test_type => $3,
cpu_mpi => $4,
cpu_openmp => $5,
status => "open",
paropt => \%task_records
);
$Experiments{$2} = \%record;
if ($Experiments{$2}{test_type} =~ /4DVAR/i) {
foreach my $task (@tasks) {
if ($task =~ /sm/i) {
print "\nNOTE: 4DVAR shared memory builds not supported. Will not compile 4DVAR for smpar; dm+sm.\n";
next;
}
push @Compiletypes, "4DVAR_$task" unless grep(/4DVAR_$task/,@Compiletypes);
}
} else {
foreach my $task (@tasks) {
my $task_escapeplus = $task;
$task_escapeplus =~ s/\+/\\+/g; # Need to escape "+" sign from "dm+sm" in the unless check
push @Compiletypes, "3DVAR_$task" unless grep(/3DVAR_$task_escapeplus/,@Compiletypes);
}
}
};
};
};
};
}
close DATA;
# If source specified on command line, use it
$Source = $Source_defined if defined $Source_defined;
# If the source is "REPO", we need to specify the location of the code repository
my $CODE_REPO = '[email protected]:wrf-model/WRF'; #We're now on Github!
if ($Source eq "REPO") {
if (defined $REPO_defined) {
if ($Fork eq "") {
$CODE_REPO = $REPO_defined;
} else {
die "\nCan not define 'repo' and 'fork' on command line; choose one or the other\n";
}
print "Using specified repository location: $CODE_REPO\n";
} elsif ($Fork eq "") {
print "Using default repository location: $CODE_REPO\n";
} else {
$CODE_REPO = "git\@github.com:$Fork/WRF";
print "Using specified repository location: $CODE_REPO\n";
}
}
if ($CODE_REPO =~ /svn-/) {
$REPO_type = 'svn';
} elsif ($CODE_REPO =~ /github/) {
$REPO_type = 'git';
} else {
$REPO_type = 'unk';
}
# Upload summary to web by default if source is head of repository;
# otherwise do not upload unless upload option is explicitly selected
my $Upload;
if ( ($Debug == 0) && ($Exec == 0) && ($Source eq "REPO") && ($Revision_defined eq "HEAD") && ($Branch eq "") && ($Fork eq "") && !(defined $Upload_defined) ) {
$Upload="yes";
print "\nSource is head of main repository: will upload summary to web when test is complete.\n\n";
} elsif ( !(defined $Upload_defined) ) {
$Upload="no";
} else {
$Upload=$Upload_defined;
}
# If specified paths are relative then point them to the full path
if ( !($Source =~ /^\//) ) {
unless ( ($Source eq "REPO") or $Exec) {$Source = $MainDir."/".$Source};
}
if ( !($Database =~ /^\//) ) {
$Database = $MainDir."/".$Database;
}
if ( !($Baseline =~ /^\//) ) {
$Baseline = $MainDir."/".$Baseline;
}
# If the test database doesn't exist, quit right away
unless ( -e "$Database" ) {
die "DATABASE NOT FOUND: '$Database'\nQuitting $0...\n";
}
die "\nCompiler '$Compiler_defined' is not supported on this $System $Local_machine machine, '$Machine_name'. \n Supported combinations are: \n Linux x86_64 (yellowstone): ifort, gfortran, pgf90 \n Linux x86_64 (loblolly): ifort, gfortran, pgf90 \n Linux i486, i586, i686: ifort, gfortran, pgf90 \n Darwin (Mac OSx): pgf90, g95 \n\n" unless (keys %Experiments) > 0 ;
printf "Finished parsing the table, the experiments are : \n";
&show_tests(%Experiments);
if ($Arch eq "Linux") { #If on a machine with modules, make sure we have the right modules loaded
if ( !( $ENV{TACC_FAMILY_COMPILER} =~ m/$module_loaded/) ) {; # Check ENV variable for current module
print "\n!!!!! ERROR ERROR ERROR !!!!!\n";
print "You have specified the $module_loaded compiler, but the $ENV{TACC_FAMILY_COMPILER} module is loaded!";
print "\n!!!!! ERROR ERROR ERROR !!!!!\n";
&print_help_and_die;
}
}
# If a command-line test list was specified, remove other tests
if ( $test_list_string ) {
my @tests = split(/ /,$test_list_string);
my %New_Experiments ;
print "\nTest list was specified on the command line.\n";
print "Removing all but specified tests.\n";
undef @Compiletypes; # Need to reset @Compiletypes and re-populate it, since we may prune some test types all together
my $testfound = 0;
foreach my $testname (@tests) {
foreach my $name (keys %Experiments) {
if ($name eq $testname) {
$New_Experiments{$name} = $Experiments{$name};
$testfound = 1;
my $newtask = $New_Experiments{$name}{test_type};
foreach my $par (keys %{$Experiments{$name}{paropt}}) {
if ($newtask =~ /4DVAR/i) {
push @Compiletypes, "4DVAR_$par" unless grep(/4DVAR_$par/,@Compiletypes);
} else {
my $task_escapeplus = $par;
$task_escapeplus =~ s/\+/\\+/g; # Need to escape "+" sign from "dm+sm" in the unless check
push @Compiletypes, "3DVAR_$par" unless grep(/3DVAR_$task_escapeplus/,@Compiletypes);
}
}
}
}
printf "\nWARNING : Test $testname not found!\n" unless ($testfound > 0);
$testfound = 0;
}
die "\n\nNO VALID TESTS MATCH FROM tests= OPTION AND $Testfile\n\nQUITTING TEST SCRIPT\n\n" unless (%New_Experiments);
%Experiments = %New_Experiments;
printf "\nNew list of experiments : \n";
&show_tests(%Experiments);
}
# Set paths to necessary utilities, set BUFR read ENV variables if needed
if ($Arch eq "Linux") {
$diffwrfdir = "~/bin/";
}
# What time is it?
#
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);
$year += 1900;
$mon += 101; $mon = sprintf("%02d", $mon % 100);
$mday += 100; $mday = sprintf("%02d", $mday % 100);
$hour += 100; $hour = sprintf("%02d", $hour % 100);
$min += 100; $min = sprintf("%02d", $min % 100);
$sec += 100; $sec = sprintf("%02d", $sec % 100);
#For cycle jobs, WRF must exist. Will add capability to compile WRF in the (near?) future
if (grep { $Experiments{$_}{test_type} =~ /cycl/i } keys %Experiments) {
if (-e "$libdir/WRFV3_$Compiler/main/wrf.exe") {
print "Will use WRF code in $libdir/WRFV3_$Compiler for CYCLING test\n";
} else {
print "\n$libdir/WRFV3_$Compiler/main/wrf.exe DOES NOT EXIST\n";
print "Removing cycling tests...\n\n";
foreach my $name (keys %Experiments) {
foreach my $type ($Experiments{$name}{test_type}) {
if ($type =~ /CYCLING/i) {
delete $Experiments{$name};
print "Deleting Cycling experiment $name from test list.\n\n";
next ;
}
}
}
printf "\nNew list of experiments : \n";
&show_tests(%Experiments);
}
}
# Check for correct modules which have been specially built on Yellowstone with compatible NETCDF/HDF5 (sigh...why can't we just have these compatible for ALL modules...)
if ( ($Machine_name eq "yellowstone") and ($use_HDF5 eq "yes") ) {
if ( ($Compiler eq "gfortran") and ($Compiler_version =~ /6.1.0/) ) {
die "Your netCDF build is located at $ENV{NETCDF} and does not appear to be version 4.4.1\nYou need to use netCDF 4.4.1 with this compiler for compatability with HDF5 (don't blame me, blame CISL)\n" unless ($ENV{NETCDF} =~ /4.4.1/);
} elsif ( ($Compiler eq "gfortran") and ($Compiler_version =~ /5.3.0/) ) {
die "Your netCDF build is located at $ENV{NETCDF} and does not appear to be version 4.4.0\nYou need to use netCDF 4.4.0 with this compiler for compatability with HDF5 (don't blame me, blame CISL)\n" unless ($ENV{NETCDF} =~ /4.4.0/);
}
}
# If exec=yes, collect version info and skip compilation
if ($Exec) {
print "Option exec=yes specified; checking previously built code for revision number\n";
($Revision,$Revision_date) = &get_repo_revision("WRFDA_$Compiletypes[0]");
if ($#Compiletypes > 0 ) {
print "Ensuring that all compiled code is the same version\n";
foreach my $compile_check (@Compiletypes[1..$#Compiletypes]) { # $Revision already has revision info for Compiletypes[0]; skip it
my ($revision_check,undef) = &get_repo_revision("WRFDA_$compile_check");
die "\nCheck your existing code: WRFDA_$Compiletypes[0] ($Revision) and WRFDA_$compile_check ($revision_check) do not appear to be built from the same version of code!\n" unless ($revision_check eq $Revision);
}
}
chomp($Revision);
print "All code checks out; revision is $Revision\n";
goto "SKIP_COMPILE";
}
# Set necessary environment variables for compilation
$ENV{J}="-j $Parallel_compile_num";
if (defined $NETCDF4_defined && $NETCDF4_defined ne 'no') {
$ENV{NETCDF4}='1';
print "\nWill compile with NETCDF4 features turned on\n\n";
}
if (defined $CLOUDCV_defined && $CLOUDCV_defined ne 'no') {
$ENV{CLOUD_CV}='1';
print "\nWill compile for CLOUD_CV option\n\n";
}
if ( (-d "$libdir/HDF5_$Compiler\_$Compiler_version") && ($use_HDF5 eq "yes")) {
$ENV{HDF5}="$libdir/HDF5_$Compiler\_$Compiler_version";
print "Found HDF5 in directory $libdir/HDF5_$Compiler\_$Compiler_version\n";
} else {
unless (-d "$libdir/HDF5_$Compiler\_$Compiler_version") {print "\nDirectory $libdir/HDF5_$Compiler\_$Compiler_version DOES NOT EXIST!\n"};
print "\nNot using HDF5\n";
delete $ENV{HDF5};
}
if (&revision_conditional('<',$Revision_defined,'r9362') > 0) {
print "Code version detected to be prior to r9362; setting CRTM=1\n";
$ENV{CRTM} = 1;
}
# Set RTTOV environment variable if appropriate
$RTTOV_dir = "$libdir/rttov_$Compiler\_$Compiler_version";
if ( (-d $RTTOV_dir) and ($use_RTTOV=~/yes/i) ) {
$ENV{RTTOV} = $RTTOV_dir;
print "Using RTTOV libraries in $RTTOV_dir\n";
} else {
if (-d $RTTOV_dir) {
print "\$use_RTTOV is not set to 'yes'\n";
print "Not compiling with RTTOV: RTTOV tests will fail!\n";
} else {
print "$RTTOV_dir DOES NOT EXIST\n";
print "RTTOV Libraries have not been compiled with $Compiler version $Compiler_version\nRTTOV tests will fail!\n";
}
$RTTOV_dir = undef;
delete $ENV{RTTOV}
}
#################### BEGIN COMPILE SECTION ####################
# Compilation variables
my $WRFPLUSDIR;
my $WRFPLUSDIR_serial;
# Check for WRFPLUS builds if we need to build 4DVAR
if (grep /4DVAR_dmpar/,@Compiletypes) {
# Set WRFPLUS_DIR Environment variable
$WRFPLUSDIR = "$libdir/WRFPLUSV3_$Compiler\_$Compiler_version";
chomp($WRFPLUSDIR);
print "4DVAR dmpar tests specified: checking for WRFPLUS code in directory $WRFPLUSDIR.\n";
if (-d $WRFPLUSDIR) {
print "Checking WRFPLUS revision ...\n";
($WRFPLUS_Revision,undef) = &get_repo_revision("$WRFPLUSDIR");
} else {
print "\n$WRFPLUSDIR DOES NOT EXIST\n";
print "\nNOT COMPILING FOR 4DVAR DMPAR!\n";
@Compiletypes = grep(!/4DVAR_dmpar/,@Compiletypes);
foreach my $name (keys %Experiments) {
if ($Experiments{$name}{test_type} =~ /4DVAR/i) {
foreach my $par (keys %{$Experiments{$name}{paropt}}) {
if ($par =~ /dmpar/i) {
delete $Experiments{$name}{paropt}{$par};
if ((keys %{$Experiments{$name}{paropt}}) > 0) {
print "\nDeleting 4DVAR dmpar experiment $name from test list.\n";
} else {
delete $Experiments{$name};
print "\nDeleting 4DVAR experiment $name from test list.\n";
next ;
}
}
}
}
}
printf "\nNew list of experiments : \n";
&show_tests(%Experiments);
}
}
if (grep /4DVAR_serial/,@Compiletypes) {
# Set WRFPLUS_DIR Environment variable
$WRFPLUSDIR_serial = "$libdir/WRFPLUSV3_$Compiler\_$Compiler_version\_serial";
chomp($WRFPLUSDIR_serial);
print "4DVAR serial tests specified: checking for WRFPLUS code in directory $WRFPLUSDIR_serial.\n";
if (-d $WRFPLUSDIR_serial) {
if ($WRFPLUS_Revision eq "NONE") {
print "Checking WRFPLUS revision ...\n";
($WRFPLUS_Revision,undef) = &get_repo_revision("$WRFPLUSDIR_serial");
}
} else {
print "\n$WRFPLUSDIR_serial DOES NOT EXIST\n";
print "\nNOT COMPILING FOR 4DVAR SERIAL!\n";
@Compiletypes = grep(!/4DVAR_serial/,@Compiletypes);
foreach my $name (keys %Experiments) {
if ($Experiments{$name}{test_type} =~ /4DVAR/i) {
foreach my $par (keys %{$Experiments{$name}{paropt}}) {
if ($par =~ /serial/i) {
delete $Experiments{$name}{paropt}{$par};
if ((keys %{$Experiments{$name}{paropt}}) > 0) {
print "\nDeleting 4DVAR serial experiment $name from test list.\n";
} else {
delete $Experiments{$name};
print "\nDeleting 4DVAR experiment $name from test list.\n";
next ;
}
}
}
}
}
printf "\nNew list of experiments : \n";
&show_tests(%Experiments);
}
}
####################### BEGIN COMPILE LOOP ########################
foreach my $compile_type (@Compiletypes) { #I *WOULD* use the $_ built-in variable but Perl hates me I guess
my @tmparray = split /_/,$compile_type;
my $ass_type = $tmparray[0]; my $par_type = $tmparray[1];
print "\n================================================\nWill compile for $compile_type\n";
if ($ass_type eq "4DVAR") {
# Set WRFPLUS_DIR for this build
if ($par_type eq "dmpar") {
print "Will use WRFPLUS code in $WRFPLUSDIR for $compile_type compilation\n";
$ENV{WRFPLUS_DIR} = "$WRFPLUSDIR";
} elsif ($par_type eq "serial") {
print "Will use WRFPLUS code in $WRFPLUSDIR_serial for $compile_type compilation\n";
$ENV{WRFPLUS_DIR} = $WRFPLUSDIR_serial;
}
}
# Get WRFDA code
if ( -e "WRFDA_$compile_type" && -r "WRFDA_$compile_type" ) {
printf "Deleting the old WRFDA_$compile_type directory ... \n";
#Delete in background to save time rather than using "rmtree"
! system("mv", "WRFDA_$compile_type", ".WRFDA_$compile_type") or die "Can not move 'WRFDA_$compile_type' to '.WRFDA_$compile_type for deletion': $!\n";
! system("rm -rf .WRFDA_$compile_type &") or die "Can not remove WRFDA_$compile_type: $!\n";
}
if ($Source eq "REPO") {
print "Getting the code from repository $CODE_REPO to WRFDA_$compile_type ...\n";
&repo_checkout ($REPO_type,$CODE_REPO,$Revision_defined,$Branch,"WRFDA_$compile_type");
if ($Revision_defined eq 'HEAD') {
($Revision,$Revision_date) = &get_repo_revision("WRFDA_$compile_type");
} else {
$Revision = $Revision_defined;
(undef,$Revision_date) = &get_repo_revision("WRFDA_$compile_type");
}
print "Revision $Revision successfully checked out to WRFDA_$compile_type.\n";
} else {
if ( ($Source =~ /\.tar$/) or ($Source =~ /\.tar\.gz$/) ) { #if tar file, untar; otherwise assume this is a directory containing code
print "Untarring the code from $Source to WRFDA_$compile_type ...\n";
! system("tar", "xf", $Source) or die "Can not open $Source: $!\n";
! system("mv", "WRFDA", "WRFDA_$compile_type") or die "Can not move 'WRFDA' to 'WRFDA_$compile_type': $!\n";
} else {
print "Copying the code from $Source to WRFDA_$compile_type ...\n";
! system("cp","-rf",$Source,"WRFDA_$compile_type") or die "Can not copy '$Source' to 'WRFDA_$compile_type': $!\n";
}
($Revision,$Revision_date) = &get_repo_revision("WRFDA_$compile_type");
}
# Change the working directory to WRFDA:
chdir "WRFDA_$compile_type" or die "Cannot chdir to WRFDA_$compile_type: $!\n";
# Delete unnecessary directories to test code in release style
if ( -e "chem" && -r "chem" ) {
print "Deleting chem directory ... ";
rmtree ("chem") or die "Can not rmtree chem :$!\n";
}
if ( -e "dyn_nmm" && -r "dyn_nmm" ) {
print "Deleting dyn_nmm directory ... ";
rmtree ("dyn_nmm") or die "Can not rmtree dyn_nmm :$!\n";
}
if ( -e "hydro" && -r "hydro" ) {
print "Deleting hydro directory ...\n";
rmtree ("hydro") or die "Can not rmtree hydro :$!\n";
}
# Locate the compile options base on the $compiler:
my $readme; my $writeme; my $pid;
if ($ass_type eq "4DVAR") {
$pid = open2( $readme, $writeme, './configure','4dvar');
} else {
$pid = open2( $readme, $writeme, './configure','wrfda');
}
print $writeme "1\n";
my @output = <$readme>;
waitpid($pid,0);
close ($readme);
close ($writeme);
my $option;
$count = 0;
my $par_type_escapeplus = $par_type;
$par_type_escapeplus =~ s/\+/\\+/g; # Need to escape "+" sign from "dm+sm" in the unless check
foreach (@output) {
my $config_line = $_ ;
if (($config_line=~ m/(\d+)\.\s\($par_type_escapeplus\) .* $Compiler\/$CCompiler .*/ix) &&
! ($config_line=~/Cray/i) &&
! ($config_line=~/PGI accelerator/i) &&
! ($config_line=~/-f90/i) &&
! ($config_line=~/POE/) &&
! ($config_line=~/Xeon/) &&
! ($config_line=~/SGI MPT/i) &&
! ($config_line=~/MIC/) &&
! ($config_line=~/Open MPI/) &&
! ($config_line=~/HSW/) ) {
$Compile_options{$1} = $par_type;
$option = $1;
$count++;
}
}
if ($count > 1) {
print "Number of options found: $count\n";
print "Options: ";
while ( my ($key, $value) = each(%Compile_options) ) {
print "$key,";
}
print "\nSelecting option '$option'. THIS MAY NOT BE IDEAL.\n";
} elsif ($count < 1 ) {
die "\nSHOULD NOT DIE HERE\nCompiler '$Compiler_defined' is not supported on this $System $Local_machine machine, '$Machine_name'. \n Supported combinations are: \n Linux x86_64 (Yellowstone): ifort, gfortran, pgf90 \n Linux x86_64 (loblolly): ifort, gfortran, pgf90 \n Linux i486, i586, i686: ifort, gfortran, pgf90 \n Darwin (visit-a05): pgf90, g95 \n\n";
}
printf "Found $ass_type compilation option for %6s, option %2d.\n",$Compile_options{$option}, $option;
# Run clean and configure scripts
my $status = system ('./clean -a 1>/dev/null 2>/dev/null');
die "clean -a exited with error $!\n" unless $status == 0;
if ($ass_type eq "4DVAR") {
if ( $Debug == 2 ) {
$pid = open2($readme, $writeme, './configure','-D','4dvar');
} elsif ( $Debug == 1 ) {
$pid = open2($readme, $writeme, './configure','-d','4dvar');
} else {
$pid = open2($readme, $writeme, './configure','4dvar');
}
} else {
if ( $Debug == 2 ) {
$pid = open2($readme, $writeme, './configure','-D','wrfda');
} elsif ( $Debug == 1 ) {
$pid = open2($readme, $writeme, './configure','-d','wrfda');
} else {
$pid = open2($readme, $writeme, './configure','wrfda');
}
}
print $writeme "$option\n";
@output = <$readme>;
waitpid($pid,0);
close ($readme);
close ($writeme);
# Compile the code
if ( $Debug == 2 ) {
printf "Compiling in super-debug mode, compilation optimizations turned off, debugging features turned on.\n";
} elsif ( $Debug == 1 ) {
printf "Compiling in debug mode, compilation optimizations turned off.\n";
}
if ( ($Parallel_compile_num > 1) && ($Machine_name =~ /yellowstone/i) ) {
printf "Submitting job to compile WRFDA_$compile_type with %10s for %6s ....\n", $Compiler, $Compile_options{$option};
# Generate the LSF job script
open FH, ">job_compile_${ass_type}_$Compile_options{$option}_opt${option}.csh" or die "Can not open job_compile_${ass_type}_${option}.csh to write. $! \n";
print FH '#!/bin/csh'."\n";
print FH '#',"\n";
print FH '# LSF batch script'."\n";
print FH '#'."\n";
print FH "#BSUB -J compile_${ass_type}_$Compile_options{$option}_opt${option}"."\n";
print FH "#BSUB -q ".$Compile_queue."\n";
print FH "#BSUB -n $Parallel_compile_num\n";
print FH "#BSUB -o job_compile_${ass_type}_$Compile_options{$option}_opt${option}.output"."\n";
print FH "#BSUB -e job_compile_${ass_type}_$Compile_options{$option}_opt${option}.error"."\n";
print FH "#BSUB -W 100"."\n";
print FH "#BSUB -P $Project"."\n";
printf FH "#BSUB -R span[ptile=%d]"."\n", $Parallel_compile_num;
print FH "\n";
print FH "setenv J '-j $Parallel_compile_num'\n";
if (defined $RTTOV_dir) {print FH "setenv RTTOV $RTTOV_dir\n"};
print FH "./compile all_wrfvar >& compile.log.$Compile_options{$option}\n";
print FH "\n";
close (FH);
# Submit the job
my $submit_message;
$submit_message = `bsub < job_compile_${ass_type}_$Compile_options{$option}_opt${option}.csh`;
if ($submit_message =~ m/.*<(\d+)>/) {;
print "Job ID for $ass_type $Compiler option $Compile_options{$option} is $1 \n";
$compile_job_array{$1} = "${ass_type}_$Compile_options{$option}";
push (@compile_job_list,$1);
} else {
die "\nFailed to submit $ass_type compile job for $Compiler option $Compile_options{$option}!\n";
};
} else { #Serial compile OR non-Yellowstone compile
printf "Compiling WRFDA_$compile_type with %10s for %6s ....\n", $Compiler, $Compile_options{$option};
# Fork each compilation
$pid = fork();
if ($pid) {
print "pid is $pid, parent $$\n";
push(@childs, $pid);
} elsif ($pid == 0) {
my $begin_time = gettimeofday();
if (! open FH, ">compile.log.$Compile_options{$option}") {
print "Can not open file compile.log.$Compile_options{$option}.\n";
exit 1;
}
$pid = open (PH, "./compile all_wrfvar 2>&1 |");
while (<PH>) {
print FH;
}
close (PH);
close (FH);
my $end_time = gettimeofday();
# Check if the compilation is successful:
@exefiles = &check_executables;
if (@exefiles) {
print "\nThe following executables were not created for $compile_type: check your compilation log.\n";
foreach ( @exefiles ) {
print " $_\n";
}
exit 2
}
# Check other executables for failures
printf "\nCompilation of WRFDA_$compile_type with %10s compiler for %6s was successful.\nCompilation took %4d seconds.\n",
$Compiler, $Compile_options{$option}, ($end_time - $begin_time);
# Save the compilation log file
if (!-d "$MainDir/regtest_compile_logs/$year$mon$mday") {
if (! mkpath("$MainDir/regtest_compile_logs/$year$mon$mday")) {
print "mkpath failed: $!\n$MainDir/regtest_compile_logs/$year$mon$mday";
exit 4;
}
}
if (! copy( "compile.log.$Compile_options{$option}", "../regtest_compile_logs/$year$mon$mday/compile_$ass_type.log.$Compile_options{$option}_$Compiler\_$hour:$min:$sec" )) {
print "Copy failed: $!\ncompile.log.$Compile_options{$option}\n../regtest_compile_logs/$year$mon$mday/compile_$ass_type.log.$Compile_options{$option}_$Compiler\_$hour:$min:$sec";
exit 5;
}
exit 0; #Exit child process! Quite important or else you get stuck forever!
} else {
die "couldn't fork: $!\n";
}
}
# Back to the upper directory:
chdir ".." or die "Cannot chdir to .. : $!\n";
}
####################### END COMPILE LOOP ########################
#For forked jobs, need to wait for forked compilations to complete
foreach (@childs) {
my $res = waitpid($_, 0);
unless ($? == 0) {
die "Child process exited with error: ", $_;
}
}
#Because Perl is Perl, must create a temporary array to modify while in "for" loop
my @temparray = @compile_job_list;
# For batch build, keep track of ongoing compile jobs, continue when finished.
while ( @compile_job_list ) {
# Remove '|' from start of "compile_job_list"
for my $i ( 0 .. $#compile_job_list ) {
my $jobnum = $compile_job_list[$i];
my $job_feedback = `bjobs $jobnum`;
if ( ($job_feedback =~ m/RUN/) || ( $job_feedback =~ m/PEND/ ) ) {; # Still pending or running
next;
}
# Job not found, so assume it's done!
my $bhist = `bhist $jobnum`;
my @jobhist = split('\s+',$bhist);
print "Job $compile_job_array{$jobnum} (job number $jobnum) is finished!\n It took $jobhist[24] seconds\n";
# Save the compilation log file
if (!-d "$MainDir/regtest_compile_logs/$year$mon$mday") {
mkpath("$MainDir/regtest_compile_logs/$year$mon$mday") or die "mkpath failed: $!\n$MainDir/regtest_compile_logs/$year$mon$mday";
}
my @details = split /_/, $compile_job_array{$jobnum};
copy( "WRFDA_$compile_job_array{$jobnum}/compile.log.$details[1]", "regtest_compile_logs/$year$mon$mday/compile_$details[1].log.$details[0]_$Compiler\_$hour:$min:$sec" ) or die "Copy failed: $!\nWRFDA_$compile_job_array{$jobnum}/compile.log.$details[1]\nregtest_compile_logs/$year$mon$mday/compile_$details[1].log.$details[0]_$Compiler\_$hour:$min:$sec";
# Check that all executables were created
@exefiles = &check_executables("WRFDA_$compile_job_array{$jobnum}");
if (@exefiles) {
print "\nThe following executables were not created for $details[0], $details[1]: check your compilation log.\n";
foreach ( @exefiles ) {
print " $_\n";
}
die "Exiting $0\n";
}