| 1 | #include <iostream>
|
|---|
| 2 | using namespace std;
|
|---|
| 3 | #include <chrono>
|
|---|
| 4 | using namespace chrono;
|
|---|
| 5 | #include <uActor.h>
|
|---|
| 6 |
|
|---|
| 7 | int Actors = 40'000, Set = 100, Rounds = 100, Processors = 1, Batch = 1, Qscale = 512; // default values '
|
|---|
| 8 | struct Msg : public uActor::Message {} msg;
|
|---|
| 9 | time_point<steady_clock> starttime;
|
|---|
| 10 |
|
|---|
| 11 | _Actor Executor {
|
|---|
| 12 | static int ids; // unique actor id generator
|
|---|
| 13 | Executor * gstart;
|
|---|
| 14 | int id, rounds, recs = 0, sends = 0;
|
|---|
| 15 |
|
|---|
| 16 | Allocation receive( Message & msg ) {
|
|---|
| 17 | Case ( Msg, msg ) {
|
|---|
| 18 | if ( recs == rounds ) return Finished;
|
|---|
| 19 | if ( recs % Batch == 0 ) {
|
|---|
| 20 | for ( int i = 0; i < Batch; i += 1 ) {
|
|---|
| 21 | gstart[sends % Set] | msg; // cycle through set
|
|---|
| 22 | sends += 1;
|
|---|
| 23 | } // for
|
|---|
| 24 | } // if
|
|---|
| 25 | recs += 1;
|
|---|
| 26 | } // Case
|
|---|
| 27 | return Nodelete;
|
|---|
| 28 | } // Executor::receive
|
|---|
| 29 | public:
|
|---|
| 30 | Executor() {
|
|---|
| 31 | id = ids++; // unique actor id, and start point for cycle
|
|---|
| 32 | gstart = &this[id / Set * Set - id]; // remember group-start array-element
|
|---|
| 33 | rounds = Set * Rounds; // send at least one message to each group member
|
|---|
| 34 | } // Executor::Executor
|
|---|
| 35 | }; // Executor
|
|---|
| 36 | int Executor::ids = 0;
|
|---|
| 37 |
|
|---|
| 38 | size_t malloc_unfreed() { return 16621; } // unfreed storage from locale
|
|---|
| 39 | //size_t malloc_expansion() { return 2 * 1024 * 1024; }
|
|---|
| 40 |
|
|---|
| 41 | int main( int argc, char * argv[] ) {
|
|---|
| 42 | locale loc( getenv("LANG") );
|
|---|
| 43 | cout.imbue( loc );
|
|---|
| 44 |
|
|---|
| 45 | switch ( argc ) {
|
|---|
| 46 | case 7:
|
|---|
| 47 | if ( strcmp( argv[6], "d" ) != 0 ) { // default ?
|
|---|
| 48 | Qscale = stoi( argv[6] );
|
|---|
| 49 | if ( Qscale < 1 ) goto Usage;
|
|---|
| 50 | } // if
|
|---|
| 51 | case 6:
|
|---|
| 52 | if ( strcmp( argv[5], "d" ) != 0 ) { // default ?
|
|---|
| 53 | Batch = stoi( argv[5] );
|
|---|
| 54 | if ( Batch < 1 ) goto Usage;
|
|---|
| 55 | } // if
|
|---|
| 56 | case 5:
|
|---|
| 57 | if ( strcmp( argv[4], "d" ) != 0 ) { // default ?
|
|---|
| 58 | Processors = stoi( argv[4] );
|
|---|
| 59 | if ( Processors < 1 ) goto Usage;
|
|---|
| 60 | } // if
|
|---|
| 61 | case 4:
|
|---|
| 62 | if ( strcmp( argv[3], "d" ) != 0 ) { // default ?
|
|---|
| 63 | Rounds = stoi( argv[3] );
|
|---|
| 64 | if ( Rounds < 1 ) goto Usage;
|
|---|
| 65 | } // if
|
|---|
| 66 | case 3:
|
|---|
| 67 | if ( strcmp( argv[2], "d" ) != 0 ) { // default ?
|
|---|
| 68 | Set = stoi( argv[2] );
|
|---|
| 69 | if ( Set < 1 ) goto Usage;
|
|---|
| 70 | } // if
|
|---|
| 71 | case 2:
|
|---|
| 72 | if ( strcmp( argv[1], "d" ) != 0 ) { // default ?
|
|---|
| 73 | Actors = stoi( argv[1] );
|
|---|
| 74 | if ( Actors < 1 || Actors <= Set || Actors % Set != 0 ) goto Usage;
|
|---|
| 75 | } // if
|
|---|
| 76 | case 1: // use defaults
|
|---|
| 77 | break;
|
|---|
| 78 | default:
|
|---|
| 79 | Usage:
|
|---|
| 80 | cerr << "Usage: " << argv[0]
|
|---|
| 81 | << " [ actors (> 0 && > set && actors % set == 0 ) | 'd' (default " << Actors
|
|---|
| 82 | << ") ] [ set (> 0) | 'd' (default " << Set
|
|---|
| 83 | << ") ] [ rounds (> 0) | 'd' (default " << Rounds
|
|---|
| 84 | << ") ] [ processors (> 0) | 'd' (default " << Processors
|
|---|
| 85 | << ") ] [ batch (> 0) | 'd' (default " << Batch
|
|---|
| 86 | << ") ] [ queue scale (> 0) | 'd' (default " << Qscale
|
|---|
| 87 | << ") ]" << endl;
|
|---|
| 88 | exit( EXIT_FAILURE );
|
|---|
| 89 | } // switch
|
|---|
| 90 |
|
|---|
| 91 | uExecutor * executor = new uExecutor( Processors, Processors, // too large for task stack
|
|---|
| 92 | Processors == 1 ? 1 : Processors * Qscale, true, 0 );
|
|---|
| 93 | uActor::start( executor ); // start actor system
|
|---|
| 94 | Executor * actors = new Executor[Actors]; // too many actors for task stack
|
|---|
| 95 | starttime = steady_clock::now();
|
|---|
| 96 | for ( int i = 0; i < Actors; i += 1 ) actors[i] | msg; // start actors
|
|---|
| 97 | uActor::stop(); // wait for all actors to terminate
|
|---|
| 98 | cout << (steady_clock::now() - starttime).count() / 1'000'000'000.0 << endl; // '
|
|---|
| 99 | delete [] actors;
|
|---|
| 100 | delete executor;
|
|---|
| 101 | // malloc_stats();
|
|---|
| 102 | } // main
|
|---|
| 103 |
|
|---|
| 104 | // /usr/bin/time -f "%Uu %Ss %Er %Mkb" a.out
|
|---|
| 105 |
|
|---|
| 106 | // Local Variables: //
|
|---|
| 107 | // compile-command: "u++-work -g -Wall -Wextra -O3 -nodebug -DNDEBUG -multi uC++Executor.cc" //
|
|---|
| 108 | // End: //
|
|---|