1 | #include <actor.hfa> |
---|
2 | #include <fstream.hfa> |
---|
3 | #include <stdlib.hfa> |
---|
4 | #include <string.h> |
---|
5 | #include <stdio.h> |
---|
6 | |
---|
7 | // int Actors = 40000, Set = 100, Rounds = 100, Processors = 1, Batch = 1, BufSize = 10; // default values |
---|
8 | int Actors = 1000, Set = 20, Rounds = 10, Processors = 1, Batch = 1, BufSize = 10; // other defaults for test to run in reasonable time |
---|
9 | |
---|
10 | static int ids = 0; |
---|
11 | struct d_actor { |
---|
12 | inline actor; |
---|
13 | d_actor * gstart; |
---|
14 | int id, rounds, recs, sends; |
---|
15 | }; |
---|
16 | void ?{}( d_actor & this ) with(this) { |
---|
17 | ((actor &)this){}; |
---|
18 | id = ids++; |
---|
19 | gstart = (&this + (id / Set * Set - id)); // remember group-start array-element |
---|
20 | rounds = Set * Rounds; // send at least one message to each group member |
---|
21 | recs = 0; |
---|
22 | sends = 0; |
---|
23 | } |
---|
24 | |
---|
25 | struct d_msg { inline message; } shared_msg; |
---|
26 | void ?{}( d_msg & this ) { ((message &) this){ Nodelete }; } |
---|
27 | |
---|
28 | Allocation receive( d_actor & this, d_msg & msg ) with( this ) { |
---|
29 | if ( recs == rounds ) return Finished; |
---|
30 | if ( recs % Batch == 0 ) { |
---|
31 | for ( i; Batch ) { |
---|
32 | gstart[sends % Set] | shared_msg; |
---|
33 | sends += 1; |
---|
34 | } |
---|
35 | } |
---|
36 | recs += 1; |
---|
37 | return Nodelete; |
---|
38 | } |
---|
39 | |
---|
40 | int main( int argc, char * argv[] ) { |
---|
41 | switch ( argc ) { |
---|
42 | case 7: |
---|
43 | if ( strcmp( argv[6], "d" ) != 0 ) { // default ? |
---|
44 | BufSize = atoi( argv[6] ); |
---|
45 | if ( BufSize < 0 ) goto Usage; |
---|
46 | } // if |
---|
47 | case 6: |
---|
48 | if ( strcmp( argv[5], "d" ) != 0 ) { // default ? |
---|
49 | Batch = atoi( argv[5] ); |
---|
50 | if ( Batch < 1 ) goto Usage; |
---|
51 | } // if |
---|
52 | case 5: |
---|
53 | if ( strcmp( argv[4], "d" ) != 0 ) { // default ? |
---|
54 | Processors = atoi( argv[4] ); |
---|
55 | if ( Processors < 1 ) goto Usage; |
---|
56 | } // if |
---|
57 | case 4: |
---|
58 | if ( strcmp( argv[3], "d" ) != 0 ) { // default ? |
---|
59 | Rounds = atoi( argv[3] ); |
---|
60 | if ( Rounds < 1 ) goto Usage; |
---|
61 | } // if |
---|
62 | case 3: |
---|
63 | if ( strcmp( argv[2], "d" ) != 0 ) { // default ? |
---|
64 | Set = atoi( argv[2] ); |
---|
65 | if ( Set < 1 ) goto Usage; |
---|
66 | } // if |
---|
67 | case 2: |
---|
68 | if ( strcmp( argv[1], "d" ) != 0 ) { // default ? |
---|
69 | Actors = atoi( argv[1] ); |
---|
70 | if ( Actors < 1 || Actors <= Set || Actors % Set != 0 ) goto Usage; |
---|
71 | } // if |
---|
72 | case 1: // use defaults |
---|
73 | break; |
---|
74 | default: |
---|
75 | Usage: |
---|
76 | sout | "Usage: " | argv[0] |
---|
77 | | " [ actors (> 0 && > set && actors % set == 0 ) | 'd' (default " | Actors |
---|
78 | | ") ] [ set (> 0) | 'd' (default " | Set |
---|
79 | | ") ] [ rounds (> 0) | 'd' (default " | Rounds |
---|
80 | | ") ] [ processors (> 0) | 'd' (default " | Processors |
---|
81 | | ") ] [ batch (> 0) | 'd' (default " | Batch |
---|
82 | | ") ] [ buffer size (>= 0) | 'd' (default " | BufSize |
---|
83 | | ") ]" ; |
---|
84 | exit( EXIT_FAILURE ); |
---|
85 | } // switch |
---|
86 | |
---|
87 | |
---|
88 | executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * 512, true, BufSize }; |
---|
89 | |
---|
90 | printf("starting\n"); |
---|
91 | |
---|
92 | start_actor_system( e ); |
---|
93 | |
---|
94 | printf("started\n"); |
---|
95 | |
---|
96 | d_actor actors[ Actors ]; |
---|
97 | |
---|
98 | for ( i; Actors ) { |
---|
99 | actors[i] | shared_msg; |
---|
100 | } // for |
---|
101 | |
---|
102 | printf("stopping\n"); |
---|
103 | |
---|
104 | stop_actor_system(); |
---|
105 | |
---|
106 | printf("stopped\n"); |
---|
107 | |
---|
108 | return 0; |
---|
109 | } |
---|