Git Product home page Git Product logo

Comments (3)

lindstro avatar lindstro commented on August 18, 2024 1

const_array classes do indeed support private_const_view, e.g.,

typedef zfp::internal::dim1::private_const_view<const_array1> private_const_view;

This is the only way to access a const_array in a thread-safe manner. Here's a simple example:

#include <iostream>
#include <omp.h>
#include "zfp/constarray1.hpp"

int main()
{
  // initialize 1D array to linear ramp
  const size_t n = 100;
  double field[n];
  for (size_t i = 0; i < n; i++)
    field[i] = i; 

  // initialize fixed-precision const_array, a
  zfp::const_array1d a(n, zfp_config_precision(10), field);

  // output const_array in parallel
  #pragma omp parallel
  {
    // obtain a thread-safe view, v, of a
    zfp::const_array1d::private_const_view v(&a);

    // determine loop bounds for this thread
    int thread = omp_get_thread_num();
    int threads = omp_get_num_threads();
    size_t min = (thread + 0) * n / threads;
    size_t max = (thread + 1) * n / threads;

    // loop over indices assigned to this thread
    for (size_t i = min; i < max; i++) {
      double val = v(i);
      // serialize output
      #pragma omp critical
      {
        std::cout << i << " " << val << std::endl;
      }
    }
  }

  return 0;
}

Specifying cache_size=0 merely sets the cache size to its default of roughly √n elements for an array with n elements and is unrelated to thread safety.

from zfp.

aavbsouza avatar aavbsouza commented on August 18, 2024

I was mistaken, is possible to use the private_const_view with the const_array classes

from zfp.

aavbsouza avatar aavbsouza commented on August 18, 2024

Hello @lindstro thank you detailed reply.

from zfp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.