<commit_before>#include <boost/test/unit_test.hpp>

#include "SoftXMT.hpp"
#include "GlobalTaskJoiner.hpp"
#include "ForkJoin.hpp"
#include "AsyncParallelFor.hpp"
#include "Delegate.hpp"

#include "PerformanceTools.hpp"

BOOST_AUTO_TEST_SUITE( AsyncParallelFor_Global_tests );

#define MAX_NODES 8
#define SIZE 10000
int64_t done[SIZE*MAX_NODES] = {0};
int64_t count2 = 0;
int64_t global_count = 0;
int64_t local_count = 0;

void loop_body(int64_t start, int64_t num ) {
  /*BOOST_MESSAGE( "execute [" << start << ","
            << start+num << ") with thread " << CURRENT_THREAD->id );*/
  BOOST_CHECK( num <= FLAGS_async_par_for_threshold );
  for (int i=start; i<start+num; i++) {
    int64_t marked = SoftXMT_delegate_fetch_and_add_word( make_global( &done[i], 0 ), 1 );
    BOOST_CHECK( marked == 0 );

    SoftXMT_delegate_fetch_and_add_word( make_global( &global_count, 0 ), 1 ); 
    local_count++;
  }
}

struct parallel_func : public ForkJoinIteration {
  void operator()(int64_t nid) const {
    int64_t start = nid * SIZE;
    int64_t iters = SIZE;

    global_joiner.reset();
    async_parallel_for<&loop_body, &joinerSpawn<&loop_body> > ( start, iters ); 
    global_joiner.wait();
  }
};


// don't care what type goes into the GlobalAddress
typedef int64_t dummy_t;

void loop_body2(int64_t start, int64_t num, GlobalAddress<dummy_t> shared_arg_packed) {
  /*BOOST_MESSAGE( "execute [" << start << ","
            << start+num << ") with thread " << CURRENT_THREAD->id );*/
  BOOST_CHECK( num <= FLAGS_async_par_for_threshold );
  int64_t origin = reinterpret_cast<int64_t>(shared_arg_packed.pointer());
  for (int i=start; i<start+num; i++) {
    SoftXMT_delegate_fetch_and_add_word( make_global( &count2, origin ), 1 );

    SoftXMT_delegate_fetch_and_add_word( make_global( &global_count, 0 ), 1 ); 
    local_count++;
  }
}

LOOP_FUNCTION(check_count2, nid) {
  BOOST_CHECK( count2 == SIZE );
}

struct parallel_func2 : public ForkJoinIteration {
  void operator()(int64_t nid) const {
    local_count = 0;

    int64_t start = nid * SIZE;
    int64_t iters = SIZE;

    // pack an argument into the global address (hack).
    // This is useful if we need just the node() from the global address and want to use the other
    // bits for something else.
    int64_t shared_arg = SoftXMT_mynode(); 
    GlobalAddress<dummy_t> shared_arg_packed = make_global( reinterpret_cast<dummy_t*>(shared_arg) );

    global_joiner.reset();
    async_parallel_for<dummy_t,&loop_body2, &joinerSpawn_hack<dummy_t,&loop_body2> >(start,iters,shared_arg_packed);
    global_joiner.wait();
  }
};


  
LOOP_FUNCTION(func_enable_google_profiler, nid) {<commit_msg>Remove unneccessary '&'s before template params in AsyncParallelFor test.<commit_after>#include <boost/test/unit_test.hpp>

#include "SoftXMT.hpp"
#include "GlobalTaskJoiner.hpp"
#include "ForkJoin.hpp"
#include "AsyncParallelFor.hpp"
#include "Delegate.hpp"

#include "PerformanceTools.hpp"

BOOST_AUTO_TEST_SUITE( AsyncParallelFor_Global_tests );

#define MAX_NODES 8
#define SIZE 10000
int64_t done[SIZE*MAX_NODES] = {0};
int64_t count2 = 0;
int64_t global_count = 0;
int64_t local_count = 0;

void loop_body(int64_t start, int64_t num ) {
  /*BOOST_MESSAGE( "execute [" << start << ","
            << start+num << ") with thread " << CURRENT_THREAD->id );*/
  BOOST_CHECK( num <= FLAGS_async_par_for_threshold );
  for (int i=start; i<start+num; i++) {
    int64_t marked = SoftXMT_delegate_fetch_and_add_word( make_global( &done[i], 0 ), 1 );
    BOOST_CHECK( marked == 0 );

    SoftXMT_delegate_fetch_and_add_word( make_global( &global_count, 0 ), 1 ); 
    local_count++;
  }
}

struct parallel_func : public ForkJoinIteration {
  void operator()(int64_t nid) const {
    int64_t start = nid * SIZE;
    int64_t iters = SIZE;

    global_joiner.reset();
    async_parallel_for<loop_body, joinerSpawn<loop_body> > ( start, iters ); 
    global_joiner.wait();
  }
};


// don't care what type goes into the GlobalAddress
typedef int64_t dummy_t;

void loop_body2(int64_t start, int64_t num, GlobalAddress<dummy_t> shared_arg_packed) {
  /*BOOST_MESSAGE( "execute [" << start << ","
            << start+num << ") with thread " << CURRENT_THREAD->id );*/
  BOOST_CHECK( num <= FLAGS_async_par_for_threshold );
  int64_t origin = reinterpret_cast<int64_t>(shared_arg_packed.pointer());
  for (int i=start; i<start+num; i++) {
    SoftXMT_delegate_fetch_and_add_word( make_global( &count2, origin ), 1 );

    SoftXMT_delegate_fetch_and_add_word( make_global( &global_count, 0 ), 1 ); 
    local_count++;
  }
}

LOOP_FUNCTION(check_count2, nid) {
  BOOST_CHECK( count2 == SIZE );
}

struct parallel_func2 : public ForkJoinIteration {
  void operator()(int64_t nid) const {
    local_count = 0;

    int64_t start = nid * SIZE;
    int64_t iters = SIZE;

    // pack an argument into the global address (hack).
    // This is useful if we need just the node() from the global address and want to use the other
    // bits for something else.
    int64_t shared_arg = SoftXMT_mynode(); 
    GlobalAddress<dummy_t> shared_arg_packed = make_global( reinterpret_cast<dummy_t*>(shared_arg) );

    global_joiner.reset();
    async_parallel_for<dummy_t,loop_body2,joinerSpawn_hack<dummy_t,loop_body2> >(start,iters,shared_arg_packed);
    global_joiner.wait();
  }
};


  
LOOP_FUNCTION(func_enable_google_profiler, nid) {
{'fraction_non_alphanumeric': 0.12186513096786179, 'fraction_numerical': 0.024150102173509196, 'mean_word_length': 4.488277268093782, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 25, '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': '4926319', 'n_tokens_mistral': 2051, 'n_tokens_neox': 1925, 'n_words': 417}