-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
1679 lines (1389 loc) · 56.4 KB
/
main.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
#include <iostream>
#include <mpi.h>
#include <getopt.h>
#include <cmath>
#include "utils.h"
#include "Dataset.h"
#include "tune_svm.h"
#include "read_dataset.h"
#define CLI_ARGS true
#define IMPLEMENTED_KERNELS 4
#define NUMBER_OF_HYPER_PARAMETERS 4
#define NUMBER_OF_PERFORMANCE_CHECKS 20
#define SHOW_LOGTIME true
#define DEBUG_MAIN false
#define MAX_HP_VALUES 20 // HP are hyperparameters, not health points
std::string read_env_var(const std::string &name) {
std::string ris;
if (getenv(name.c_str())) {
ris = getenv(name.c_str());
} else {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[WARN] The environment variable " << name << " was not found.\n";
// exit(1);
return "FALSE";
}
#if DEBUG_MAIN
std::cout << name << ": " << ris << "\n\n";
#endif
return ris;
}
enum train_flag { training = 0, testing = 1, tuning = 2, undefined = -1 } flag;
#if CLI_ARGS
/**
* Display cli args help
*/
void print_usage(const std::string &program_name) {
std::cout << "Usage: " << program_name << " options [ -l tuning/training/testing ... ]\n"
<< " -h --help Display this usage information.\n"
<< " -l --logic Program logic, may be 'training', 'testing' or 'tuning'.\n"
<< " -p --parallel-tuning Set tuning logic. Can be 'split' or 'sequential'. Default adapts to dataset size.\n"
<< " -i --path1 First input path supplied, may be interpreted as training path or testing path.\n"
<< " -I --path2 Second input path supplied, in tuning logic is interpreted as validation.\n"
<< " -t --target-column Index of the target column.\n"
<< " -c --columns Number of columns in the dataset.\n"
<< " -r --row1 Number of rows in the first supplied dataset.\n"
<< " -R --row2 Number of rows in the second supplied dataset.\n"
<< " -H --hyperparameters-path Path to the hyperparameters file.\n"
<< " -s --svm-path Path to the SVM file.\n"
<< " -S --save-dir-path Folder path for saving SVM files.\n"
<< " -M --tuning-table-dir-path Folder path for saving tuning table files.\n"
<< " -k --kernel Kernel type, may be 'l' (linear), 'p' (polynomial), 'r' (rbf) or 's' (sigmoid).\n"
<< " -C --cost Cost parameter.\n"
<< " -g --gamma Gamma parameter.\n"
<< " -O --coef0 Coef0 parameter.\n"
<< " -d --degree Degree parameter.\n"
<< " -T --learning_rate Learning rate parameter.\n"
<< " -E --eps Epsilon parameter.\n"
<< " -L --limit Limit parameter.\n"
<< " -v --verbose Print verbose messages.\n"
<< std::endl;
exit(0);
}
#endif
int main(int argc, char *argv[]) {
/* Initialize MPI ------------------------------------ */
MPI_Init(&argc, &argv);
// Get the rank of the process
int process_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &process_rank);
// Get the number of processes
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
/* --------------------------------------------------- */
bool performance_checks = read_env_var("PERFORMANCE_CHECKS").at(0) == 'T';
int control = 0;
if (performance_checks) {
MPI_Barrier(MPI_COMM_WORLD);
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "This step is done by process 0 only to benchmark the speed of for loops\n";
double start = MPI_Wtime(), end = 0;
for (int i = 0; i < 1000; i++) {}
end = MPI_Wtime();
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "On this platform, a for loop cycle alone takes an average of " << (end - start) / 1000
<< "\n\n";
}
MPI_Barrier(MPI_COMM_WORLD);
}
std::string filepath_training;
std::string filepath_validation;
std::string filepath_testing;
std::string filepath_svm;
std::string hparameters_path;
std::string save_svm_dir_path;
std::string save_tune_dir_path;
bool defaul = true;
#if CLI_ARGS
int next_option = 0;
/* A string listing valid short options letters. */
const char *const short_options = "l:p:i:I:t:c:r:R:H:s:S:M:k:C:g:O:d:T:E:L:vh";
/* An array describing valid long options. */
const struct option long_options[] = {
{"help", 0, nullptr, 'h'},
{"logic", 1, nullptr, 'l'},
{"parallel-tuning", 1, nullptr, 'p'},
{"path1", 1, nullptr, 'i'},
{"path2", 2, nullptr, 'I'},
{"target-column", 1, nullptr, 't'},
{"columns", 1, nullptr, 'c'},
{"row1", 1, nullptr, 'r'},
{"row2", 2, nullptr, 'R'},
{"hyperparameters-path", 2, nullptr, 'H'},
{"svm-path", 2, nullptr, 's'},
{"save-dir-path", 2, nullptr, 'S'},
{"tuning-table-dir-path", 2, nullptr, 'M'},
{"kernel", 2, nullptr, 'k'},
{"cost", 2, nullptr, 'C'},
{"gamma", 2, nullptr, 'g'},
{"coef0", 2, nullptr, 'O'},
{"degree", 2, nullptr, 'd'},
{"learning_rate", 2, nullptr, 'T'},
{"eps", 2, nullptr, 'E'},
{"limit", 2, nullptr, 'L'},
{"verbose", 0, nullptr, 'v'},
{nullptr, 0, nullptr, 0}
};
/**
* Parameters initialization
*/
bool tuning_logic = true;
bool logic_set_flag = false;
std::string p1;
std::string p2;
int rows_t = 0;
int rows_v = 0;
int target_column = 0;
int columns = 0;
char ker_type = DEFAULT_KERNEL;
double Cost = DEFAULT_COST;
double gamma = DEFAULT_GAMMA;
double coef0 = DEFAULT_INTERCEPT;
double degree = DEFAULT_DEGREE;
double lr = DEFAULT_LEARNING_RATE;
double limit = DEFAULT_LEARNING_RATE;
double eps = DEFAULT_EPS;
bool verbose = false;
flag = undefined;
std::string program_name = argv[0];
/**
* CLI arguments parsing
*/
do {
next_option = getopt_long(argc, argv, short_options, long_options, nullptr);
switch (next_option) {
case 'h': {
/* -h or --help */
print_usage(program_name);
break;
}
case 'l': {
/* -l or --logic */
if (strcmp(optarg, "training") == 0) {
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Logic set to training." << std::endl;
}
flag = training;
} else if (strcmp(optarg, "testing") == 0) {
flag = testing;
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Logic set to testing." << std::endl;
}
} else if (strcmp(optarg, "tuning") == 0) {
flag = tuning;
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Logic set to tuning." << std::endl;
}
} else {
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[ERROR] Invalid logic argument, please use training, testing or tuning.\n";
}
exit(1);
}
break;
}
case 'p': { /* -p or --parallel-tuning */
if (strcmp(optarg, "sequential") == 0) {
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout
<< "[INFO] Tuning logic set to sequential. All processes will go through sequential tuning with parallel training.\n";
}
tuning_logic = false;
logic_set_flag = true;
} else if (strcmp(optarg, "split") == 0) {
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout
<< "[INFO] Tuning logic set to split. Processes will split the available combination.\n";
}
tuning_logic = true;
logic_set_flag = true;
} else {
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout
<< "[INFO] Tuning logic has not been set. Processes will adapt with respect to dataset size.\n";
}
}
break;
}
case 'i': { /* -i or --path1 */
p1 = optarg;
break;
}
case 'I': {
p2 = optarg;
break;
}
case 't': {
/* -t or --target_column */
target_column = std::atoi(optarg);
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Target column set to " << target_column << std::endl;
}
break;
}
case 'c': { /* -c or --columns */
columns = std::atoi(optarg);
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Number of columns set to " << columns << std::endl;
}
break;
}
case 'r': { /* -r or --row1 */
rows_t = std::atoi(optarg);
break;
}
case 'R': { /* -R or --row2 */
rows_v = std::atoi(optarg);
break;
}
case 'H': { /* -H or --hparameters_path */
hparameters_path = optarg;
break;
}
case 's': { /* -s or --svm-path */
char *tmp = optarg;
if (tmp) {
filepath_svm = optarg;
}
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] SVM file path set to " << filepath_svm << std::endl;
}
break;
}
case 'S': { /* -s or --svm_path */
save_svm_dir_path = optarg;
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] SVM save file path set to " << filepath_svm << std::endl;
}
break;
}
case 'M': { /* -s or --svm_path */
save_tune_dir_path = optarg;
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Tuning table file path set to " << filepath_svm << std::endl;
}
break;
}
case 'k': { /* -k or --kernel */
ker_type = *optarg;
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Kernel type set to `" << ker_type << "`" << std::endl;
}
break;
}
case 'C': { /* -C or --cost */
Cost = std::stod(optarg);
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Cost parameter set to " << Cost << std::endl;
}
break;
}
case 'g': { /* -g or --gamma */
gamma = std::stod(optarg);
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Gamma parameter set to " << gamma << std::endl;
}
break;
}
case 'O': { /* -O or --coef0 */
coef0 = std::stod(optarg);
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Coef0 parameter set to " << coef0 << std::endl;
}
break;
}
case 'd': { /* -d or --degree */
degree = std::stoi(optarg);
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Degree parameter set to " << degree << std::endl;
}
break;
}
case 'T': { /* -T or --learning_rate */
lr = std::stod(optarg);
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Learning rate set to " << lr << std::endl;
break;
}
case 'E': { /* -E or --eps */
eps = std::stod(optarg);
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Epsilon set to " << eps << std::endl;
}
break;
}
case 'L': { /* -L or --limit */
limit = std::stod(optarg);
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Limit value set to " << limit << std::endl;
}
break;
}
case 'v': { /* -v or --verbose */
verbose = true;
break;
}
case '?': { /* The user specified an invalid option */
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[WARN] You entered an invalid option." << std::endl;
}
print_usage(program_name);
}
case -1: { /* Done with options */
break;
}
default: {
/* Something else unexpected */
exit(1);
}
}
} while (next_option != -1);
/* ----------- Checks ---------------- */
if (!p1.empty()) {
if ((flag == training) || (flag == tuning)) {
filepath_training = std::move(p1);
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Training file path set to " << filepath_training << std::endl;
}
} else if (flag == testing) {
filepath_testing = std::move(p1);
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Testing file path set to " << filepath_testing << std::endl;
}
} else {
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[ERROR] Program logic (tuning, training, testing) was not defined.\n";
}
exit(1);
}
} else {
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[ERROR] Argument path1 was not supplied.\n";
}
exit(1);
}
if (!p2.empty()) {
if (flag != tuning) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[WARN] You entered path2, but logic was not set to tuning." << std::endl;
} else {
filepath_validation = std::move(p2);
}
} else {
if (flag == tuning) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[ERROR] Path2 was not entered, but logic was set to tuning." << std::endl;
exit(1);
}
}
if (!logic_set_flag) {
tuning_logic = rows_t > columns;
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout
<< "[WARN] Tuning logic was not supplied, therefore the program will adapt based on the supplied datasets\n";
}
}
if ((rows_v != 0) && flag != tuning) {
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[WARN] Rows for validation dataset were passed, but the programi is not on tuning mode.\n"
<< std::endl;
}
}
if (target_column == 0 || columns == 0 || rows_t == 0) {
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[ERROR] A lenght was not entered\nRows=" << rows_t << "\ncolumns=" << columns
<< "\ntarget column=" << target_column << std::endl;
}
exit(1);
}
if (flag == undefined) {
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[ERROR] Program logic was not defined " << std::endl;
}
exit(1);
}
if (flag == testing && filepath_svm.empty()) {
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[ERROR] SVM path was not provided! " << std::endl;
}
exit(1);
}
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Cli arguments successfully parsed.\n" << std::endl;
}
#else
/**
* Flag selection (training, testing, tuning)
*/
flag = tuning;
bool tuning_logic = true;
filepath_training = "./data/iris_train.csv";
filepath_validation = "./data/iris_validation.csv";
save_svm_dir_path = "./saved_svm";
std::string filepath_hyper_parameters = "hpc2022/data/hyperparameters.csv";
filepath_svm = "hpc2022/saved_svm/sigmoids_C0.500000_G0.010000_O0.000000.svm";
int rows_t = 70, rows_v = 30, columns = 5, target_column = 5;
char ker_type = 's';
bool verbose = false;
double Cost = 0.5;
double gamma = 0.01;
double coef0 = 0;
double degree = 0;
const double lr = 0.0001;
const double limit = 0.1;
const double eps = DEFAULT_EPS;
#endif
/**
* Program startup
*/
auto *time_checks = (double *) calloc(NUMBER_OF_PERFORMANCE_CHECKS, sizeof(double));
int time_iterator = 0;
if (performance_checks) {
MPI_Barrier(MPI_COMM_WORLD);
*(time_checks + time_iterator) = MPI_Wtime(); // start
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Program starts at time " << *(time_checks + time_iterator) << "\n" << std::endl;
}
++time_iterator;
}
/**
* Switch block begins
*/
switch (flag) {
/// Training case
case train_flag::training : {
/* ------------------------------------------------------------------------------------------------------------------ */
if (performance_checks) {
MPI_Barrier(MPI_COMM_WORLD);
*(time_checks + time_iterator) = MPI_Wtime(); // start
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Reading training dataset starts at time " << *(time_checks + time_iterator)
<< std::endl;
}
++time_iterator;
}
Dataset df_train = read_dataset(filepath_training, rows_t, columns, target_column);
if (performance_checks) {
MPI_Barrier(MPI_COMM_WORLD);
*(time_checks + time_iterator) = MPI_Wtime(); // start
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] It took "
<< *(time_checks + time_iterator) - *(time_checks + time_iterator - 1)
<< " seconds\n" << std::endl;
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] svm preparation starts at time " << *(time_checks + time_iterator)
<< std::endl;
}
++time_iterator;
}
Kernel_SVM svm;
svm.verbose = verbose;
set_kernel_function(&svm, ker_type);
double params[4] = {Cost, gamma, coef0, degree};
if (performance_checks) {
MPI_Barrier(MPI_COMM_WORLD);
*(time_checks + time_iterator) = MPI_Wtime(); // start
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] It took "
<< *(time_checks + time_iterator) - *(time_checks + time_iterator - 1)
<< " seconds\n" << std::endl;
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Training starts at time " << *(time_checks + time_iterator) << std::endl;
}
++time_iterator;
}
parallel_train(df_train, &svm, params, lr, limit, MASTER_PROCESS, world_size, true, save_svm_dir_path, 0, eps);
if (performance_checks) {
MPI_Barrier(MPI_COMM_WORLD);
*(time_checks + time_iterator) = MPI_Wtime(); // start
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] It took "
<< *(time_checks + time_iterator) - *(time_checks + time_iterator - 1)
<< " seconds\n" << std::endl;
}
++time_iterator;
}
break;
}
/// Testing case
case train_flag::testing: {
/* ------------------------------------------------------------------------------------------------------------------ */
if (performance_checks) {
MPI_Barrier(MPI_COMM_WORLD);
*(time_checks + time_iterator) = MPI_Wtime(); // start
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Reading testing dataset starts at time " << *(time_checks + time_iterator)
<< std::endl;
}
++time_iterator;
}
Dataset df_test = read_dataset(filepath_testing, rows_t, columns, target_column);
if (performance_checks) {
MPI_Barrier(MPI_COMM_WORLD);
*(time_checks + time_iterator) = MPI_Wtime(); // start
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] It took "
<< *(time_checks + time_iterator) - *(time_checks + time_iterator - 1)
<< " seconds\n" << std::endl;
}
++time_iterator;
}
Kernel_SVM svm;
if (performance_checks) {
MPI_Barrier(MPI_COMM_WORLD);
*(time_checks + time_iterator) = MPI_Wtime(); // start
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Reading svm file starts at time " << *(time_checks + time_iterator)
<< std::endl;
}
++time_iterator;
}
read_svm(&svm, filepath_svm);
if (performance_checks) {
MPI_Barrier(MPI_COMM_WORLD);
*(time_checks + time_iterator) = MPI_Wtime(); // start
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] It took "
<< *(time_checks + time_iterator) - *(time_checks + time_iterator - 1)
<< " seconds\n" << std::endl;
}
++time_iterator;
}
svm.verbose = true;
if (performance_checks) {
MPI_Barrier(MPI_COMM_WORLD);
*(time_checks + time_iterator) = MPI_Wtime(); // start
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Parallel test starts at time " << *(time_checks + time_iterator) << std::endl;
}
++time_iterator;
}
parallel_test(df_test, &svm, MASTER_PROCESS, world_size);
if (performance_checks) {
MPI_Barrier(MPI_COMM_WORLD);
*(time_checks + time_iterator) = MPI_Wtime(); // start
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] It took "
<< *(time_checks + time_iterator) - *(time_checks + time_iterator - 1)
<< " seconds\n" << std::endl;
}
++time_iterator;
}
break;
}
/// Tuning case
case train_flag::tuning: {
/* ------------------------------------------------------------------------------------------------------------------ */
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Training Dataset filepath: " << filepath_training << std::endl;
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] The dataset has " << rows_t << " rows and " << columns << " columns." << std::endl;
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Validation Dataset filepath: " << filepath_validation << std::endl;
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] The dataset has " << rows_v << " rows and " << columns << " columns." << std::endl;
}
#if CLI_ARGS
double *cost_array;
double *gamma_array;
double *coef0_array;
double *degree_array;
int cost_array_size, gamma_array_size, coef0_array_size, degree_array_size;
cost_array = (double *) calloc(sizeof(double), MAX_HP_VALUES);
gamma_array = (double *) calloc(sizeof(double), MAX_HP_VALUES);
coef0_array = (double *) calloc(sizeof(double), MAX_HP_VALUES);
degree_array = (double *) calloc(sizeof(double), MAX_HP_VALUES);
if (!hparameters_path.empty()) {
cost_array_size = 0;
gamma_array_size = 0;
coef0_array_size = 0;
degree_array_size = 0;
read_hyperparameters(hparameters_path,
cost_array, cost_array_size,
gamma_array, gamma_array_size,
coef0_array, coef0_array_size,
degree_array, degree_array_size);
cost_array = (double *) realloc(cost_array, cost_array_size * sizeof(double));
gamma_array = (double *) realloc(gamma_array, gamma_array_size * sizeof(double));
coef0_array = (double *) realloc(coef0_array, coef0_array_size * sizeof(double));
degree_array = (double *) realloc(degree_array, degree_array_size * sizeof(double));
defaul = false;
} else {
if (process_rank == MASTER_PROCESS) {
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[WARN] Tuning file was not supplied, using default values\n";
}
cost_array_size = DEFAULT_COST_SIZE;
gamma_array_size = DEFAULT_GAMMA_SIZE;
coef0_array_size = DEFAULT_COEF0_SIZE;
degree_array_size = DEFAULT_DEGREE_SIZE;
cost_array = DEFAULT_COST_ARRAY;
gamma_array = DEFAULT_GAMMA_ARRAY;
coef0_array = DEFAULT_COEF0_ARRAY;
degree_array = DEFAULT_DEGREE_ARRAY;
}
if (process_rank == MASTER_PROCESS) {
std::cout << "\n" << std::endl;
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Cost array size: " << cost_array_size << std::endl;
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Cost array:";
for (int i = 0; i < cost_array_size; i++) {
std::cout << cost_array[i] << " ";
}
std::cout << std::endl;
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Gamma array size: " << gamma_array_size << std::endl;
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Gamma array:";
for (int i = 0; i < gamma_array_size; i++) {
std::cout << gamma_array[i] << " ";
}
std::cout << std::endl;
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Coef0 array size: " << coef0_array_size << std::endl;
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Coef0 array:";
for (int i = 0; i < coef0_array_size; i++) {
std::cout << coef0_array[i] << " ";
}
std::cout << std::endl;
#if SHOW_LOGTIME
logtime();
#endif
std::cout << "[INFO] Degree array size: " << degree_array_size << std::endl;
#if SHOW_LOGTIME