source: doc/theses/colby_parsons_MMAth/benchmarks/waituntil/ucpp/future.cc

Last change on this file was b5e3a80, checked in by caparson <caparson@…>, 2 years ago

refactored waituntil future benchmarks and updated runscript

  • Property mode set to 100644
File size: 3.6 KB
Line 
1#include <iostream>
2using namespace std;
3#include <uFuture.h>
4
5// #define ANDOR
6
7size_t Processors = 2, Time = 10;
8size_t globalTotal = 0;
9volatile bool done_loop = false;
10volatile bool client_done = false;
11volatile bool server_done = false;
12
13Future_ISM<size_t> A, B, C;
14
15static inline void wait() {
16 #ifdef OR
17 _Select( A ) { A(); }
18 or _Select( B ) { B(); }
19 or _Select( C ) { C(); }
20 #endif
21 #ifdef AND
22 _Select( A ) { A(); }
23 and _Select( B ) { B(); }
24 #endif
25 #ifdef AND3
26 _Select( A ) { A(); }
27 and _Select( B ) { B(); }
28 and _Select( C ) { C(); }
29 #endif
30 #ifdef ANDOR
31 _Select( A ) { A(); }
32 and _Select( B ) { B(); }
33 or _Select( C ) { C(); }
34 #endif
35 #ifdef ORAND
36 (_Select( A ) { A(); }
37 or _Select( B ) { B(); })
38 and _Select( C ) { C(); }
39 #endif
40 #ifdef BASIC
41 A();
42 #endif
43}
44
45static inline void fulfill( size_t i ) {
46 #ifdef OR
47 if ( i % 3 == 0 ) {
48 A.delivery(i);
49 } else if ( i % 3 == 1 ) {
50 B.delivery(i);
51 } else {
52 C.delivery(i);
53 }
54 #endif
55 #ifdef AND
56 if ( i % 2 == 0 ) {
57 A.delivery(i);
58 B.delivery(i);
59 } else {
60 B.delivery(i);
61 A.delivery(i);
62 }
63 #endif
64 #ifdef AND3
65 if ( i % 6 == 0 ) {
66 A.delivery(i);
67 B.delivery(i);
68 C.delivery(i);
69 } else if ( i % 6 == 1 ) {
70 A.delivery(i);
71 C.delivery(i);
72 B.delivery(i);
73 } else if ( i % 6 == 2 ) {
74 B.delivery(i);
75 A.delivery(i);
76 C.delivery(i);
77 } else if ( i % 6 == 3 ) {
78 B.delivery(i);
79 C.delivery(i);
80 A.delivery(i);
81 } else if ( i % 6 == 4 ) {
82 C.delivery(i);
83 A.delivery(i);
84 B.delivery(i);
85 } else if ( i % 6 == 5 ) {
86 C.delivery(i);
87 B.delivery(i);
88 A.delivery(i);
89 }
90 #endif
91 #ifdef ANDOR
92 if ( i % 4 == 0 ) {
93 A.delivery(i);
94 B.delivery(i);
95 } else if ( i % 4 == 1 ) {
96 A.delivery(i);
97 C.delivery(i);
98 } else if ( i % 4 == 2 ) {
99 B.delivery(i);
100 C.delivery(i);
101 } else {
102 C.delivery(i);
103 }
104 #endif
105 #ifdef ORAND
106 if ( i % 4 == 0 ) {
107 A.delivery(i);
108 C.delivery(i);
109 } else if ( i % 4 == 1 ) {
110 C.delivery(i);
111 A.delivery(i);
112 } else if ( i % 4 == 2 ) {
113 B.delivery(i);
114 C.delivery(i);
115 } else {
116 C.delivery(i);
117 B.delivery(i);
118 }
119 #endif
120 #ifdef BASIC
121 A.delivery(i);
122 #endif
123}
124
125_Task Client {
126 void main() {
127 size_t i = 0;
128 for(; !client_done; i++ ) {
129 wait();
130 A.reset();
131 B.reset();
132 C.reset();
133 done_loop = true;
134 }
135 __atomic_fetch_add( &globalTotal, i, __ATOMIC_SEQ_CST );
136 }
137};
138
139_Task Server {
140 void main() {
141 for( size_t i = 0; !server_done; i++ ) {
142 fulfill( i );
143 while( !done_loop ) {}
144 done_loop = false;
145 }
146 }
147};
148
149int main( int argc, char * argv[] ) {
150 switch ( argc ) {
151 case 2:
152 if ( strcmp( argv[1], "d" ) != 0 ) { // default ?
153 Time = atoi( argv[1] );
154 if ( Time < 0 ) goto Usage;
155 } // if
156 case 1: // use defaults
157 break;
158 default:
159 Usage:
160 cerr << "Usage: " << argv[0]
161 << "[ time (>= 0) | 'd' (default " << Time
162 << ") ]" ;
163 exit( EXIT_FAILURE );
164 } // switch
165 uProcessor p[Processors - 1];
166
167 {
168 Server s;
169 {
170 Client c;
171
172 uBaseTask::sleep( uDuration( Time ) );
173
174 client_done = true;
175 }
176 server_done = true;
177 done_loop = true;
178 }
179 cout << globalTotal << endl;
180} // main
Note: See TracBrowser for help on using the repository browser.