source: tests/concurrent/actors/executor.cfa@ d40555e

ADT ast-experimental
Last change on this file since d40555e was 4933f18, checked in by caparsons <caparson@…>, 3 years ago

added test case to types test and refactored to remove redundant ctor calls

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