<commit_before>/**
 * @file		test_threadsafe_queue.cpp
 * @ingroup
 * @author	tpan
 * @brief
 * @details
 *
 * Copyright (c) 2014 Georgia Institute of Technology.  All Rights Reserved.
 *
 * TODO add License
 */



/**
 * range_test.cpp
 * Test range class
 *  Created on: Feb 18, 2014
 *      Author: tpan
 */

#include <iostream>
#include <cstdio>

#include "concurrent/threadsafe_queue.hpp"
#include "concurrent/threadsafe_fixedsize_queue.hpp"

#include "omp.h"

using namespace bliss::concurrent;



template<typename T>
class STDQueueTest
{
  protected:
    std::queue<T> q;
    int nthreads;

  public:

    void run2(int entries) {
      T output;
      for (int i = 0; i < entries; ++i) {

        if (i % 2 == 0)
          q.push(T(i));
        else {
          T v = q.front();
          q.pop();
        }

      }
    }
};




template<typename T>
class QueueTest
{
  protected:
    bliss::concurrent::ThreadSafeQueue<T> q;
    int nthreads;

  public:
    QueueTest(int nThreads) : nthreads(nThreads) {};

    void run(int entries) {

#pragma omp parallel for default(none) shared(std::cout, q, entries) num_threads(nthreads)
      for (int i = 0; i < entries; ++i) {
        int tid = omp_get_thread_num();

        if (i < 100) {
          T output;
          bool result = q.tryPop(output);
          std::cout << "thread " << tid << " try pop: " << result << std::endl;
        }

        q.push(T(i));

        if (i % 3 == 0) {
          T output;
          q.waitAndPop(output);
          std::cout << "thread " << tid << " pop result " << output << std::endl;
        }

      }

      std::cout << "size = " << q.size() << std::endl;
    }
    void run2(int entries) {
      T output;
      for (int i = 0; i < entries; ++i) {

        if (i % 2 == 0)
          q.tryPush(T(i));
        else
            q.tryPop(output);
      }
    }
};<commit_msg>WIP: need to create a single thread to manage the MPI send/receive.  ENH: added threadsafe queues<commit_after>/**
 * @file		test_threadsafe_queue.cpp
 * @ingroup
 * @author	tpan
 * @brief
 * @details
 *
 * Copyright (c) 2014 Georgia Institute of Technology.  All Rights Reserved.
 *
 * TODO add License
 */



/**
 * range_test.cpp
 * Test range class
 *  Created on: Feb 18, 2014
 *      Author: tpan
 */

#include <iostream>
#include <cstdio>

#include "concurrent/threadsafe_queue.hpp"
#include "concurrent/threadsafe_fixedsize_queue.hpp"

#include "omp.h"

using namespace bliss::concurrent;



template<typename T>
class STDQueueTest
{
  protected:
    std::queue<T> q;
    int nthreads;

  public:

    void run2(int entries) {
      T output;
      for (int i = 0; i < entries; ++i) {

        if (i % 2 == 0)
          q.push(T(i));
        else {
          T v = q.front();
          q.pop();
        }

      }
    }
};




template<typename T>
class QueueTest
{
  protected:
    bliss::concurrent::ThreadSafeQueue<T> q;
    int nthreads;

  public:
    QueueTest(int nThreads) : q(), nthreads(nThreads) {};

    void run(int entries) {

#pragma omp parallel for num_threads(nthreads) shared(std::cout, q, entries) default(none)
      for (int i = 0; i < entries; ++i) {
        int tid = omp_get_thread_num();

        if (i < 100) {
          T output;
          bool result = q.tryPop(output);
          std::cout << "thread " << tid << " try pop: " << result << std::endl;
        }

        q.push(T(i));

        if (i % 3 == 0) {
          T output;
          q.waitAndPop(output);
          std::cout << "thread " << tid << " pop result " << output << std::endl;
        }

      }

      std::cout << "size = " << q.size() << std::endl;
    }
    void run2(int entries) {
      T output;
      for (int i = 0; i < entries; ++i) {

        if (i % 2 == 0)
          q.push(T(i));
        else
            q.tryPop(output);
      }
    }
};
{'fraction_non_alphanumeric': 0.14804177545691907, 'fraction_numerical': 0.012532637075718016, 'mean_word_length': 2.0453100158982513, 'pattern_counts': {'":': 0, '<': 75, '<?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': '7651481', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1292, 'n_words': 346}