Code Monkey home page Code Monkey logo

rcpp_progress's Introduction

R-CMD-check

RcppProgress

Build Status codecov CRAN_Status_Badge

a R package that provides a c++ interruptible progress bar with OpenMP support for c++ code in R packages:

  • check for user interrupts in your c++ code
  • display a progress bar monitoring your c++ computation
  • compatible with multi-threaded c++ code (e.g. openMP)

Installing

  • from CRAN: install.packages("RcppProgress")
  • from github: remotes::install_github('kforner/rcpp_progress')

example

see a detailed example on Rcpp Gallery: http://gallery.rcpp.org/articles/using-rcppprogress/

How to build

Prerequisites:

  • OpenMP support to use the multithreaded parallelized version. OpenMP is available in GCC >= 4.2

Just install it the usual way.

If you want more control, unarchive it, cd to the source directory, then type R CMD INSTALL . in the console.

Feedback

Please use github issues to provide feedback, report bugs and propose new features.

Contribute

Contributions are welcome! The proposed process is:

  • open an issue and propose your changes
  • fork the project
  • do a merge request
  • code review
  • merge into master

New code must be tested and documented, and also come with an example.

For developers

tests and check

If you have all the RcppProgress dependencies (and suggests) installed:

type:

  • make tests: to run the tests
  • make check: to check the package

docker-checker

A Dockerfile (<docker_checker/Dockerfile>) is provided to help building the dev environment (built on rocker/r-devel) in which to develop and test RcppProgress.

type:

  • make docker/build: to build the docker
  • make docker/run: to run a shell in the docker with the current dir mounted inside
  • make docker/check: to check the package inside the docker
  • make docker/tests: to run test tests of the package inside the docker

test on windows using rhub

make docker/run
make check_rhub_windows

rcpp_progress's People

Contributors

johannes-titz avatar karl-forner-quartz-bio avatar kforner avatar mlysy avatar nevrome avatar twolodzko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

rcpp_progress's Issues

Progress example produces extra progress symbols

I'm trying the following example in RStudio

// [[Rcpp::depends(RcppProgress)]]
#include <progress.hpp>
// [[Rcpp::export]]
double long_computation3(int nb, bool display_progress=true) {
    double sum = 0;
    Progress p(nb*nb, display_progress);
    for (int i = 0; i < nb; ++i) {
        if (Progress::check_abort() )
            return -1.0;
        for (int j = 0; j < nb; ++j) {
            p.increment(); // update progress
        sum += R::dlnorm(i+j, 0.0, 1.0, 0);
    }
    }
    return sum + nb;
}
> Rcpp::sourceCpp('rcpp_progress.cpp')
> system.time(s  <- long_computation3(3000))
|----|----|----|----|----|----|----|----|----|----|
**************************************************|
|
   user  system elapsed 
   0.96    0.00    0.97 
> system.time(s  <- long_computation3(1000))
|----|----|----|----|----|----|----|----|----|----|
**************************************************|
|
   user  system elapsed 
   0.13    0.00    0.11 
> system.time(s  <- long_computation3(10000))
|----|----|----|----|----|----|----|----|----|----|
**************************************************|
********|
   user  system elapsed 
  10.75    0.00   10.79 
> system.time(s  <- long_computation3(10000))
|----|----|----|----|----|----|----|----|----|----|
**************************************************|
********|
   user  system elapsed 
  10.89    0.00   10.93 

For long time computation, extra * are always produced.

Progress as class member?

Is there a way to have a Progress class member? That would allow me to define it only only place, rather than many times. Here is what I tried (this runs as a cpp file in Rstudio)

#include <Rcpp.h>
// [[Rcpp::plugins(cpp11)]]
// [[Rcpp::depends(RcppProgress)]]
#include <progress.hpp>
#include <progress_bar.hpp>

class Simple {
public:
  double sum;
  // I would like to do
  // Progress progressbar;
  // instead I tried
  Progress *progressbar;
  void start(int nb, bool display_progress){
    sum = 0;
    // I would like to do
    // progressbar->reset(nb*nb, display_progress);
    // or "InterruptableProgressMonitor._reset" ?
    
    // this compiles but does not work
    Progress p(nb*nb, display_progress);
    progressbar = &p;
  };
  
  bool do_something(int i, int j) {
    //the below causes a crash:
    //progressbar->increment();
    //if (Progress::check_abort() ) return false;
    sum += R::dlnorm(i+j, 0.0, 1.0, 0);
    return true;
  };
  void stop(){
    //?;
  };
  double compute(int nb, bool display_progress);   
};
  
  
double Simple::compute(int nb, bool display_progress) {
  start(nb*nb, display_progress);
  for (int i = 0; i < nb; ++i) {
    for (int j = 0; j < nb; ++j) {
      if (!do_something(i, j)) return -1; 
    }
  }
  stop();
  return sum + nb;
}

// [[Rcpp::export]]
double computecpp(int nb, bool display_progress) {
  Simple c;
  return c.compute(nb, display_progress);
}

/*** R
computecpp(300, TRUE)
*/

Please do not open the Rcpp namespace for all

@nathan-russell and I are tracking an issue in Rcpp down, which appears to be linked to RcppProgress.h.

You seem to be doing

using namespace Rcpp;

here meaning that everybody using RcppProgress now has an open and unprotected Rcpp namespace.

That is probably not good design. Could we do without that?

Multithreading agnostic progress bar (RcppParallel, pthreads, openmp)

I wrote a short gist based on the idea in this package that should work for RcppParallel and any other multithreading framework.
https://gist.github.com/traversc/8b26b9e689b23d3a174aee296c0503ca

I think this general approach would be nice to see in this package.

The changes you'd need to make are not too many. In summary:

  • counter -> std::atomic
  • increment -> counter.fetch_add(1)
  • Check for main thread -> std::this_thread::get_id()

Remove dependence on devtools

The testthat unit tests use the devtools::load_all function in order to make the contents of packages in inst/examples available to the testing suite. However, devtools itself depends on curl, which on unix systems requires a separate installation of libcurl. This is fine if you have root access, but otherwise no curl, so no devtools, so no RcppProgress.

I've looked at your unit tests and I believe they can be rewritten without the use of devtools::load_all:

  1. Most tests can be combined into single cpp files, which in turn can be compiled on-the-fly with Rcpp::sourceCpp.
  2. The test in inst/examples/RcppProgressExample checks for multiple definitions in two cpp's. Since Rcpp::sourceCpp is not intended for compiling multi-file projects, I suggest to put these test files in src and thus have them compiled with RcppProgress itself.

If you're OK with the suggestion I'm happy to get started on a pull request.

prediction of remaining time

Is it possible to implement a prediction of the time a loop monitored by rcpp_progress will take to finish? Maybe a simple extrapolation of the time needed so far?

I would love to have that feature!

R function to clear out current progress bar instances

Sometimes I have to kill a function which includes an RcppProgress bar, and then when I run it again, I get

ERROR: there is already an InterruptableProgressMonitor instance defined

It would be nice for there to be a convenience R function such as RcppProgress::clear_pbs() that would remove any InterruptableProgressBarMonitor (or similar objects) associated with the current session, so one could continue without restarting.

abort()

I'm seeing warnings from R-devel with my package that R:

Found ‘abort’, possibly from ‘abort’ (C)

in two objects. The two objects don't call stop or abort or any of that, but they do use RcppProgress, which has a function called abort(). Is it possible the new warning is related to RcppProgress?

Thanks.

Warnings on compilation when not using OpenMP

I added

// [[Rcpp::depends(RcppProgress)]]
#include <progress.hpp>
#include <progress_bar.hpp>

to my code, and now I warnings during compilation:

C:/---------/R/win-library/3.4/RcppProgress/include/interruptable_progress_monitor.hpp:101:0: warning: ignoring #pragma omp critical [-Wunknown-pragmas]
 #pragma omp critical
 ^
C:/---------/R/win-library/3.4/RcppProgress/include/interruptable_progress_monitor.hpp:143:0: warning: ignoring #pragma omp atomic [-Wunknown-pragmas]
 #pragma omp atomic
 ^
C:/---------/R/win-library/3.4/RcppProgress/include/interruptable_progress_monitor.hpp:149:0: warning: ignoring #pragma omp critical [-Wunknown-pragmas]
 #pragma omp critical

Is RcppProgress compatible with RcppParallel?

http://gallery.rcpp.org/articles/using-rcppprogress/ says that RcppProgress is compatible with multithreaded code, is there reason to believe it should work with RcppParallel? I realize this may turn out to be a question for RcppParallel, but thought I would ask here.

I had some success on Windows with the following skeleton:

struct MyWorker : public RcppParallel::Worker {
  Progress progress;
  tthread::mutex mutex;

  MyWorker(Progress& progress) : progress(progress) {  }

  void operator()(std::size_t begin, std::size_t end) {
    for (std::size_t i = begin; i < end; i++) {
      // real work here
      {
        tthread::lock_guard<tthread::mutex> guard(mutex);
        progress.increment();
        if (Progress::check_abort()) {
          return;
        }
      }
    } 
  }
};

but on Linux (admittedly only tried under a VM), I get messages along the lines of Error: C stack usage 23365264492 is too close to the limit if I increase the number of threads above 1, even with the simple parallel matrix square root example from: http://gallery.rcpp.org/articles/parallel-matrix-transform/

Is this approach doomed to failure?

Progress bar mimicking "progress" package

Thank you for providing this useful package. We have been using it to develop a new package (see here) and so far it is working very well.

I have a feature request of sorts. I'm wondering if it would be possible to provide an example class (inheriting from ProgressBar) that mimics the display of the default progress bar provided by the progress package. e.g.,

[======================================================>----------------]  77%

Or perhaps this already exists somewhere?

installed package rcpt_progress not ... available

I suspect I am doing something silly, but I installed RcppProgress on R 4.2.1. and tried to run the test

library("RcppProgress")
RcppProgress:::test_sequential(max, nb, display_progress)
Error: object 'test_sequential' not found

Similarly,
test_sequential <- function(max=100, nb=1000, display_progress=TRUE) {
.Call("test_sequential_wrapper2", max, nb, display_progress, PACKAGE = "RcppProgressExample")
invisible()
}

did not work.

It seems I have failed in installing the package, using install.packages("RcppProgress").

When I look in

/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include

the header files, for example, are missing.

I am trying to put a progress bar into some cpp code. Thank you for any help you can give me.

Elizabeth

TODO: register native routines

* checking compiled code ... NOTE
File ‘RcppProgress/libs/RcppProgress.so’:
  Found no calls to: ‘R_registerRoutines’, ‘R_useDynamicSymbols’
It is good practice to register native routines and to disable symbol
search.

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.