[a4ab235] | 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 {
|
---|
[7edf912] | 12 | inline actor;
|
---|
| 13 | d_actor * gstart;
|
---|
| 14 | int id, rounds, recs, sends;
|
---|
[a4ab235] | 15 | };
|
---|
| 16 | void ?{}( d_actor & this ) with(this) {
|
---|
[7edf912] | 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;
|
---|
[a4ab235] | 22 | }
|
---|
| 23 |
|
---|
| 24 | struct d_msg { inline message; } shared_msg;
|
---|
| 25 |
|
---|
[c880a7b] | 26 | allocation receive( d_actor & this, d_msg & msg ) with( this ) {
|
---|
[7edf912] | 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;
|
---|
[a4ab235] | 36 | }
|
---|
| 37 |
|
---|
| 38 | int main( int argc, char * argv[] ) {
|
---|
[7edf912] | 39 | switch ( argc ) {
|
---|
[a4ab235] | 40 | case 7:
|
---|
| 41 | if ( strcmp( argv[6], "d" ) != 0 ) { // default ?
|
---|
[50be8af5] | 42 | BufSize = ato( argv[6] );
|
---|
| 43 | if ( BufSize < 0 ) fallthru default;
|
---|
[a4ab235] | 44 | } // if
|
---|
| 45 | case 6:
|
---|
| 46 | if ( strcmp( argv[5], "d" ) != 0 ) { // default ?
|
---|
[50be8af5] | 47 | Batch = ato( argv[5] );
|
---|
| 48 | if ( Batch < 1 ) fallthru default;
|
---|
[a4ab235] | 49 | } // if
|
---|
| 50 | case 5:
|
---|
| 51 | if ( strcmp( argv[4], "d" ) != 0 ) { // default ?
|
---|
[50be8af5] | 52 | Processors = ato( argv[4] );
|
---|
| 53 | if ( Processors < 1 ) fallthru default;
|
---|
[a4ab235] | 54 | } // if
|
---|
| 55 | case 4:
|
---|
| 56 | if ( strcmp( argv[3], "d" ) != 0 ) { // default ?
|
---|
[50be8af5] | 57 | Rounds = ato( argv[3] );
|
---|
| 58 | if ( Rounds < 1 ) fallthru default;
|
---|
[a4ab235] | 59 | } // if
|
---|
| 60 | case 3:
|
---|
| 61 | if ( strcmp( argv[2], "d" ) != 0 ) { // default ?
|
---|
[50be8af5] | 62 | Set = ato( argv[2] );
|
---|
| 63 | if ( Set < 1 ) fallthru default;
|
---|
[a4ab235] | 64 | } // if
|
---|
| 65 | case 2:
|
---|
| 66 | if ( strcmp( argv[1], "d" ) != 0 ) { // default ?
|
---|
[50be8af5] | 67 | Actors = ato( argv[1] );
|
---|
| 68 | if ( Actors < 1 || Actors <= Set || Actors % Set != 0 ) fallthru default;
|
---|
[a4ab235] | 69 | } // if
|
---|
| 70 | case 1: // use defaults
|
---|
| 71 | break;
|
---|
| 72 | default:
|
---|
[50be8af5] | 73 | exit | "Usage: " | argv[0]
|
---|
[7edf912] | 74 | | " [ actors (> 0 && > set && actors % set == 0 ) | 'd' (default " | Actors
|
---|
[a4ab235] | 75 | | ") ] [ set (> 0) | 'd' (default " | Set
|
---|
| 76 | | ") ] [ rounds (> 0) | 'd' (default " | Rounds
|
---|
| 77 | | ") ] [ processors (> 0) | 'd' (default " | Processors
|
---|
| 78 | | ") ] [ batch (> 0) | 'd' (default " | Batch
|
---|
| 79 | | ") ] [ buffer size (>= 0) | 'd' (default " | BufSize
|
---|
| 80 | | ") ]" ;
|
---|
| 81 | } // switch
|
---|
| 82 |
|
---|
[7edf912] | 83 | executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * 512, true };
|
---|
[a4ab235] | 84 |
|
---|
[7edf912] | 85 | sout | "starting";
|
---|
[a4ab235] | 86 |
|
---|
[7edf912] | 87 | start_actor_system( e );
|
---|
[a4ab235] | 88 |
|
---|
[7edf912] | 89 | sout | "started";
|
---|
[a4ab235] | 90 |
|
---|
[7edf912] | 91 | d_actor actors[ Actors ];
|
---|
[a4ab235] | 92 |
|
---|
| 93 | for ( i; Actors ) {
|
---|
[77fd9fe2] | 94 | actors[i] | shared_msg;
|
---|
[a4ab235] | 95 | } // for
|
---|
| 96 |
|
---|
[7edf912] | 97 | sout | "stopping";
|
---|
[a4ab235] | 98 |
|
---|
[7edf912] | 99 | stop_actor_system();
|
---|
[a4ab235] | 100 |
|
---|
[7edf912] | 101 | sout | "stopped";
|
---|
[50be8af5] | 102 | }
|
---|