From karl.forner at gmail.com  Mon May  6 13:07:42 2013
From: karl.forner at gmail.com (Karl Forner)
Date: Mon, 6 May 2013 13:07:42 +0200
Subject: [Rd] Catch SIGINT from user in backend C++ code
In-Reply-To: <B09F1CDB-1596-4950-9037-9BF009C84822@massey.ac.nz>
References: <B09F1CDB-1596-4950-9037-9BF009C84822@massey.ac.nz>
Message-ID: <CAMd4_Aefa-xSZEv8bto-j_T16Gy_9N9=7khXAyKpubrwsGc8mw@mail.gmail.com>

Hello,

I once wrote  a package called RcppProgress, that you can find here:
https://r-forge.r-project.org/R/?group_id=1230
I did not try it for a long time, but it was developed to solve this
exact problem.
You can have a look the its companion package: RcppProgressExample.
Here's a link to the original announcement:
http://tolstoy.newcastle.edu.au/R/e17/devel/12/02/0443.html

Hope it helps.
Karl Forner
Quartz Bio

On Thu, May 2, 2013 at 1:50 AM, Jewell, Chris <C.P.Jewell at massey.ac.nz> wrote:
> Hi,
>
> I was wondering if anybody knew how to trap SIGINTs (ie Ctrl-C) in backend C++ code for R extensions?  I'm writing a package that uses the GPU for some hefty matrix operations in a tightly coupled parallel algorithm implemented in CUDA.
>
> The problem is that once running, the C++ module cannot apparently be interrupted by a SIGINT, leaving the user sat waiting even if they realise they've launched the algorithm with incorrect settings.  Occasionally, the SIGINT gets through and the C++ module stops.  However, this leaves the CUDA context hanging, meaning that if the algorithm is launched again R dies.  If I could trap the SIGINT, then I could make sure a) that the algorithm stops immediately, and b) that the CUDA context is destructed nicely.
>
> Is there a "R-standard" method of doing this?
>
> Thanks,
>
> Chris
>
>
> --
> Dr Chris Jewell
> Lecturer in Biostatistics
> Institute of Fundamental Sciences
> Massey University
> Private Bag 11222
> Palmerston North 4442
> New Zealand
> Tel: +64 (0) 6 350 5701 Extn: 3586
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Catch SIGINT from user in backend C++ code
Karl Forner