[Rd] Running R embedded in an mpiexec spawned process - Fatal error: you must specify '--save', '--no-save' or '--vanilla'

2013-11-20 Thread Jean-Michel.Perraud
I'd like someone familiar with the R options initialization to comment on a 
difference of behavior within/without mpiexec

I have a (.NET) application with embedded R that is proven to run in a single 
process:

./Sample1.exe

on a Debian Linux with R 3.0.2

Running the same code with mpiexec, it fails at the R engine initialization:

mpiexec -n 1 ./Sample1.exe
Fatal error: you must specify '--save', '--no-save' or '--vanilla'
-

The behavior is actually reproducible with the straight R 
mpiexec -n 1 R
Fatal error: you must specify '--save', '--no-save' or '--vanilla'
-
The following is working:
mpiexec -n 1 R --no-save

However in my Sample1 application, I do set up R init options that should be 
suitable AFAIK:

rEngine = REngine.CreateInstance("RDotNet");
StartupParameter rStartParams = new StartupParameter
{
Quiet = true,
SaveAction = StartupSaveAction.NoSave,
Slave = false,
Interactive = true,
Verbose = false,
LoadInitFile = true,
LoadSiteFile = true,
RestoreAction = StartupRestoreAction.NoRestore,
NoRenviron = false
};
rEngine.Initialize(rStartParams); // calls the R API R_SetParams, 
then setup_Rmainloop


I gather that the following is hit in src/R-3.0.2/src/unix/system.c, in the 
function Rf_initialize_R:

if (!R_Interactive && Rp->SaveAction != SA_SAVE &&
Rp->SaveAction != SA_NOSAVE)
R_Suicide(_("you must specify '--save', '--no-save' or '--vanilla'"));

I don't understand why it would complain if spawned by mpiexec and fine 
otherwise. 

I do not have a suitable debugging environment to step through a R with debug 
symbols, and no stack trace is given as console output.
As an aside, the same code (barring platform specifics) works on Windows.

Thanks




__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Running R embedded in an mpiexec spawned process - Fatal error: you must specify '--save', '--no-save' or '--vanilla'

2013-11-21 Thread Jean-Michel.Perraud
Thanks for that. It does confirm what I was starting to suspect: that the R 
engine initialization in R.NET needs a change to use the R embedding API 
functions, though mindful that the R.NET author did settle on the current 
arrangement for a pragmatic reason.
I also shamefully missed a recent post on this list, albeit not mentioning MPI, 
 https://stat.ethz.ch/pipermail/r-devel/2013-November/067951.html, by Nigel 
Delaney, which reports similar and likely related issues.

Thanks for your and Professor Ripley's feedback.
J-M

From: Gabriel Becker [gmbec...@ucdavis.edu]
Sent: Thursday, November 21, 2013 6:29 PM
To: Perraud, Jean-Michel (CLW, Black Mountain)
Cc: r-devel
Subject: Re: [Rd] Running R embedded in an mpiexec spawned process - Fatal 
error: you must specify '--save', '--no-save' or '--vanilla'

I don't have any real answers for you. Perhaps someone with more experience 
will.

This may be an R.NET issue though. I'm suprised that from your 
comment, and a very brief glance at R.NET's sourcecode,  it is 
calling setup_Rmainloop. I've successfully embedded R in C programs and the 
entrypoint I always used was Rf_initEmbeddedR. My understanding is that 
setup_Rmainloop is for the non-embedded case (R running itself).

Perhaps I'm wrong and using setup_Rmainloop is supported in the embedded case 
as well as Rf_initEmbeddedR. If not I can't offer any insight to why it usually 
works anyway other than Dr. Ripleys suggestion about stdin and mpiexec.

Sorry I can't be of more help.
~G


On Wed, Nov 20, 2013 at 10:39 PM, 
mailto:jean-michel.perr...@csiro.au>> wrote:
I'd like someone familiar with the R options initialization to comment on a 
difference of behavior within/without mpiexec

I have a (.NET) application with embedded R that is proven to run in a single 
process:

./Sample1.exe

on a Debian Linux with R 3.0.2

Running the same code with mpiexec, it fails at the R engine initialization:

mpiexec -n 1 ./Sample1.exe
Fatal error: you must specify '--save', '--no-save' or '--vanilla'
-

The behavior is actually reproducible with the straight R
mpiexec -n 1 R
Fatal error: you must specify '--save', '--no-save' or '--vanilla'
-
The following is working:
mpiexec -n 1 R --no-save

However in my Sample1 application, I do set up R init options that should be 
suitable AFAIK:

rEngine = REngine.CreateInstance("RDotNet");
StartupParameter rStartParams = new StartupParameter
{
Quiet = true,
SaveAction = StartupSaveAction.NoSave,
Slave = false,
Interactive = true,
Verbose = false,
LoadInitFile = true,
LoadSiteFile = true,
RestoreAction = StartupRestoreAction.NoRestore,
NoRenviron = false
};
rEngine.Initialize(rStartParams); // calls the R API R_SetParams, 
then setup_Rmainloop


I gather that the following is hit in src/R-3.0.2/src/unix/system.c, in the 
function Rf_initialize_R:

if (!R_Interactive && Rp->SaveAction != SA_SAVE &&
Rp->SaveAction != SA_NOSAVE)
R_Suicide(_("you must specify '--save', '--no-save' or '--vanilla'"));

I don't understand why it would complain if spawned by mpiexec and fine 
otherwise.

I do not have a suitable debugging environment to step through a R with debug 
symbols, and no stack trace is given as console output.
As an aside, the same code (barring platform specifics) works on Windows.

Thanks




__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel



--
Gabriel Becker
Graduate Student
Statistics Department
University of California, Davis

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Different behavior of the "showArgs" example (R extension manual) between gcc and Visual C++ compiled code

2012-09-11 Thread Jean-Michel.Perraud
Hi,

I am trying to implement on a Win7 box the showArgs example of section 5.10.2 
"Calling .External" of the R extension manual. I am using interchangeably gcc 
(RTools) and Visual C++ (via Makefile.win) to build a package. I get a couple 
of runtime oddities when the dll compiled with Visual C++. I'd value comments, 
observations and tips from interested readers. I tried my best to find proper 
compilation settings for VCPP, from a variety of source incl. Duncan Murdoch's 
advice.

Cheers,
J-M

OBSERVATIONS

1/ The for() loop does not hit the termination condition on args being 
R_NilValue, and ends up stuck on pointers as shown below, equality never 
reached.
args0x020e24a0  SEXPREC *
R_NilValue  0x835425ff  SEXPREC *
2/ If I force it out of the endless loop, after the function returns, I get a 
nasty "Unhandled exception at 0x6c799419 in Rgui: 0xC005: Access violation 
writing location 0x0009eee9." with a call stack as follow. I did check that the 
cdecl calling convention is used.
R.dll!6c799419()
[Frames below may be incorrect and/or missing, no symbols loaded for 
R.dll] 
R.dll!6c797736()
user32.dll!7633cd90()   
user32.dll!7636c1c2()   
Rgraphapp.dll!63551cba()

CODE

// R code
library(showArgs)
blah = as.Date('2000-01-01')
printArgs(a=1:3, b=LETTERS[1:3], blah=blah)
// END R code

// C/Cpp code:
extern "C" { // because I compile the code 'as C++' for Visual C++, for in-code 
variable declaration
SEXP __cdecl showArgs_ext(SEXP args);
}

SEXP __cdecl showArgs_ext(SEXP args)
{
// snip
args = CDR(args); /* skip 'name' */
for(int i = 0; args != R_NilValue; i++, args = CDR(args)) {
// verbatim from the manual
}
return R_NilValue;
}
// END C/Cpp code


Vcc Compilation settings:
/I"C:\bin\R\R\include" /ZI /nologo /W3 /WX- /Od /Oy- /D "_WINDLL" /D "_MBCS" 
/Gm /EHsc /RTC1 /GS /fp:precise /Za /Zc:wchar_t /Zc:forScope 
/Fp"Debug\showArgs.pch" /Fa"Debug\" /Fo"Debug\" /Fd"Debug\vc100.pdb" /Gd /TP 
/analyze- /errorReport:queue 

/OUT:"C:\\Debug\showArgs.dll" /NOLOGO /LIBPATH:"C:\bin\R\R\bin\i386" /DLL 
"Rdll.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" 
"comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" 
"uuid.lib" "odbc32.lib" "odbccp32.lib" /DEF:"showArgs-win.def" /MANIFEST 
/ManifestFile:"Debug\showArgs.dll.intermediate.manifest" /ALLOWISOLATION 
/MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG 
/PDB:"C:\\Debug\showArgs.pdb" /PGD:"C:\\Debug\showArgs.pgd" /TLBID:1 
/DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE 


ENVIRONMENT
===
- Windows 7 32 bits
- R version 2.15.0 (2012-03-30) Platform: i386-pc-mingw32/i386 (32-bit)
- RTools 2.15.0
- MS Visual Cpp 2010 (express edition)

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel