[cec2551] | 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 |
---|
| 9 | int Actors = 1000, Set = 20, Rounds = 10, Processors = 1, Batch = 1, BufSize = 10; // other defaults for test to run in reasonable time |
---|
| 10 | |
---|
| 11 | static int ids = 0; |
---|
| 12 | struct d_actor { |
---|
| 13 | inline actor; |
---|
| 14 | d_actor * gstart; |
---|
| 15 | int id, rounds, recs, sends; |
---|
| 16 | }; |
---|
| 17 | void ?{}( 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 | } |
---|
| 25 | struct d_msg { inline message; } shared_msg; |
---|
| 26 | |
---|
[84334d0] | 27 | allocation receive( d_actor & this, d_msg & msg ) with( this ) { |
---|
[cec2551] | 28 | if ( recs == rounds ) return Finished; |
---|
| 29 | if ( recs % Batch == 0 ) { |
---|
| 30 | for ( i; Batch ) { |
---|
[05956d21] | 31 | gstart[sends % Set] | shared_msg; |
---|
[cec2551] | 32 | sends += 1; |
---|
| 33 | } |
---|
| 34 | } |
---|
| 35 | recs += 1; |
---|
| 36 | return Nodelete; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | int 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 | uint64_t start_time = bench_time(); |
---|
| 90 | |
---|
| 91 | start_actor_system( e ); |
---|
| 92 | |
---|
| 93 | d_actor actors[ Actors ]; |
---|
| 94 | |
---|
| 95 | for ( i; Actors ) { |
---|
[05956d21] | 96 | actors[i] | shared_msg; |
---|
[cec2551] | 97 | } // for |
---|
| 98 | |
---|
| 99 | stop_actor_system(); |
---|
| 100 | |
---|
| 101 | uint64_t end_time = bench_time(); |
---|
| 102 | |
---|
| 103 | printf("%.2f\n", ((double)(end_time - start_time))*((double)1e-9) ); |
---|
| 104 | |
---|
| 105 | return 0; |
---|
| 106 | } |
---|