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

ADTast-experimental
Last change on this file since ab2b352 was 1950837, checked in by caparsons <caparson@…>, 20 months ago

added virtual dtor test to actor test suite, updated other relevant tests accordingly

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