[ create a new paste ] login | about

Link: http://codepad.org/W4TWL4af    [ raw code | fork ]

Evetro - C++, pasted on Jan 10:
/**
 * Parallel Code Count
 * atomic.h
 * Multi-threaded (OpenMP) code count implementation using atomic increase.
 */
#pragma once
#include "reference.h"

struct AtomicCountCodes
{
  // requires zero-filled amount array
  void operator()(const std::string &text, int amount[COUNTERS]) const
  {
    // OpenMP 2.0 doesn't parallelize if the counter is unsigned
    const std::ptrdiff_t size = text.size();
    #pragma omp parallel for
    for (std::ptrdiff_t i = 0; i < size; ++i)
    {
      int * const p = amount + static_cast<unsigned char>(text[i]);
      #pragma omp atomic
      (*p)++;
    }
  }
};


Create a new paste based on this one


Comments: