<commit_before>#ifndef TASK_HPP_
#define TASK_HPP_

#include <iostream>
#include <deque>
#include "StealQueue.hpp"
#include "cbarrier.hpp"
#include "Thread.hpp"

typedef int16_t Node;

/// Task is a function pointer and pointer to arguments
/// Ideally Task would be interface that just declares execute and makeGlobal
class Task {

    private:
        void (* fn_p)(void*);
        void* arg;
    
    public:
        Task () {}
        Task (void (* fn_p)(void*), void* arg) 
            : fn_p ( fn_p )
            , arg ( arg ) { }

        void execute( ) {
            CHECK( fn_p!=NULL ) << "fn_p=" << (void*)fn_p << "\nargs=" << (void*)arg;
            fn_p( arg );
        }
};

class TaskStatistics {
    private:
        uint64_t single_steal_successes_;
        uint64_t single_steal_fails_;
        uint64_t session_steal_successes_;
        uint64_t session_steal_fails_;
        uint64_t acquire_successes_;
        uint64_t acquire_fails_;
        uint64_t releases_;

    public:
        TaskStatistics()
            : single_steal_successes_ (0)
            , single_steal_fails_ (0)
            , session_steal_successes_ (0)
            , session_steal_fails_ (0)
            , acquire_successes_ (0)
            , acquire_fails_ (0)
            , releases_ (0)
         { }

        void record_successful_steal_session() {
            session_steal_successes_++;
        }

        void record_failed_steal_session() {
            session_steal_fails_++;
        }

        void record_successful_steal() {
            single_steal_successes_++;
        }

        void record_failed_steal() {
            single_steal_fails_++;
        }

        void record_successful_acquire() {
            acquire_successes_++;
        }
        
        void record_failed_acquire() {
            acquire_fails_++;
        }

        void record_release() {
            releases_++;
        }

        void dump();
};




template < typename T >
static Task createTask( void (* fn_p)(T), T args ) {
    Task t( reinterpret_cast< void (*) (void*) >( fn_p ), args);
    return t;
}


class TaskManager {
    private:
        std::deque<Task> privateQ; 
        StealQueue<Task> publicQ;

        bool workDone;
       
        bool doSteal;   // stealing on/off
        bool okToSteal; // steal lock
        int cbint;      // how often to make local public work visible

        // to support hierarchical dynamic load balancing
        Node localId;
        Node* neighbors;
        Node numLocalNodes;

        // steal parameters
        int chunkSize;
        
        /// Flags to save whether a worker thinks there
        /// could be work or if other workers should not<commit_msg>Explicit cast to (void*) necessary for int arguments.<commit_after>#ifndef TASK_HPP_
#define TASK_HPP_

#include <iostream>
#include <deque>
#include "StealQueue.hpp"
#include "cbarrier.hpp"
#include "Thread.hpp"

typedef int16_t Node;

/// Task is a function pointer and pointer to arguments
/// Ideally Task would be interface that just declares execute and makeGlobal
class Task {

    private:
        void (* fn_p)(void*);
        void* arg;
    
    public:
        Task () {}
        Task (void (* fn_p)(void*), void* arg) 
            : fn_p ( fn_p )
            , arg ( arg ) { }

        void execute( ) {
            CHECK( fn_p!=NULL ) << "fn_p=" << (void*)fn_p << "\nargs=" << (void*)arg;
            fn_p( arg );
        }
};

class TaskStatistics {
    private:
        uint64_t single_steal_successes_;
        uint64_t single_steal_fails_;
        uint64_t session_steal_successes_;
        uint64_t session_steal_fails_;
        uint64_t acquire_successes_;
        uint64_t acquire_fails_;
        uint64_t releases_;

    public:
        TaskStatistics()
            : single_steal_successes_ (0)
            , single_steal_fails_ (0)
            , session_steal_successes_ (0)
            , session_steal_fails_ (0)
            , acquire_successes_ (0)
            , acquire_fails_ (0)
            , releases_ (0)
         { }

        void record_successful_steal_session() {
            session_steal_successes_++;
        }

        void record_failed_steal_session() {
            session_steal_fails_++;
        }

        void record_successful_steal() {
            single_steal_successes_++;
        }

        void record_failed_steal() {
            single_steal_fails_++;
        }

        void record_successful_acquire() {
            acquire_successes_++;
        }
        
        void record_failed_acquire() {
            acquire_fails_++;
        }

        void record_release() {
            releases_++;
        }

        void dump();
};




template < typename T >
static Task createTask( void (* fn_p)(T), T args ) {
    Task t( reinterpret_cast< void (*) (void*) >( fn_p ), (void*)args);
    return t;
}


class TaskManager {
    private:
        std::deque<Task> privateQ; 
        StealQueue<Task> publicQ;

        bool workDone;
       
        bool doSteal;   // stealing on/off
        bool okToSteal; // steal lock
        int cbint;      // how often to make local public work visible

        // to support hierarchical dynamic load balancing
        Node localId;
        Node* neighbors;
        Node numLocalNodes;

        // steal parameters
        int chunkSize;
        
        /// Flags to save whether a worker thinks there
        /// could be work or if other workers should not
{'fraction_non_alphanumeric': 0.09341163516241512, 'fraction_numerical': 0.008441915947880345, 'mean_word_length': 1.845953002610966, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7019971', 'n_tokens_mistral': 1684, 'n_tokens_neox': 1617, 'n_words': 406}