-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernels.c
98 lines (72 loc) · 1.77 KB
/
kernels.c
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
/*
* Author: Chris Wailes <[email protected]>
* Project: Parallel Linear Program Solver
* Date: 2011/10/26
* Description: Kernels for different methods of solving LPs.
*/
#include <stdio.h>
// Project Includes
#include "dictionary.h"
#include "kernels.h"
#include "worker.h"
// Global Variables
extern config_t cfg;
// Functions
dict_t* general_simplex_kernel(dict_t* dict) {
uint iters = 0;
uint unprogress = 0;
double prev_objective;
elr_t el_result;
if (cfg.vv) {
printf("\t** START OF SIMPLEX **\n\n");
}
prev_objective = dict->objective_value;
while (!dict_is_final(dict) && (!cfg.simplex_limit || iters < cfg.simplex_limit)) {
if (cfg.vv) {
printf("Simplex Iteration %u:\n\n", iters);
dict_view(dict);
}
dict_select_entering_and_leaving(dict, &el_result);
if (el_result.flip) {
dict_flip_rest(dict, el_result.entering, el_result.new_rest);
} else {
dict = dict_pivot(dict, el_result.entering, el_result.leaving, el_result.new_rest, el_result.adj_amount);
}
if (cfg.profys) {
if (prev_objective == dict->objective_value) {
if (++unprogress == PROF_Y_THRESHOLD) {
cfg.blands = TRUE;
}
} else {
cfg.blands = FALSE;
unprogress = 0;
}
prev_objective = dict->objective_value;
}
++iters;
}
if (cfg.verbose) {
printf("Simplex took %d iterations.\n\n", iters);
if (cfg.vv) {
printf("\t** END OF SIMPLEX **\n\n");
}
}
return dict;
}
dict_t* kernel_select(dict_t* dict) {
switch (cfg.pmode) {
case PTHREADS:
dict = pthreads_kernel(dict);
break;
case AUTO:
case OMP:
case NONE:
default:
dict = general_simplex_kernel(dict);
break;
}
return dict;
}
inline dict_t* pthreads_kernel(dict_t* dict) {
return workers_manager(dict);
}