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