source: doc/theses/colby_parsons_MMAth/benchmarks/actors/cfa/executor.cfa @ cec2551

ADTast-experimental
Last change on this file since cec2551 was cec2551, checked in by caparson <caparson@…>, 16 months ago

added cfa benchmarks

  • Property mode set to 100644
File size: 3.0 KB
Line 
1#include <actor.hfa>
2#include <fstream.hfa>
3#include <stdlib.hfa>
4#include <string.h>
5#include <stdio.h>
6#include "bench.hfa"
7
8// int Actors = 40000, Set = 100, Rounds = 100, Processors = 1, Batch = 1, BufSize = 10; // default values
9int Actors = 1000, Set = 20, Rounds = 10, Processors = 1, Batch = 1, BufSize = 10; // other defaults for test to run in reasonable time
10
11static int ids = 0;
12struct d_actor {
13    inline actor;
14    d_actor * gstart;
15    int id, rounds, recs, sends;
16};
17void ?{}( d_actor & this ) with(this) {
18    ((actor &)this){};
19    id = ids++;
20    gstart = (&this + (id / Set * Set - id)); // remember group-start array-element
21    rounds = Set * Rounds;      // send at least one message to each group member
22    recs = 0;
23    sends = 0;
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   
87    executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * 512, true, BufSize };
88
89    // printf("starting\n");
90    uint64_t start_time = bench_time();
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    uint64_t end_time = bench_time();
107
108    printf("%.2f\n", ((double)(end_time - start_time))*((double)1e-9) );
109
110    // printf("stopped\n");
111
112    return 0;
113}
Note: See TracBrowser for help on using the repository browser.