[Rd] Plot dies with memory not mapped (segfault) (PR#9785)

2007-07-10 Thread cbaenzig
Full_Name: Clay B
Version: 2.5.0 (2007-04-23)
OS: Solaris Nevada Build 55b
Submission from: (NULL) (65.101.229.198)


I find that running this script causes R to segfault reliably. However, running
just for one system at a time (modifying the for loop updating iter to run just
for a system at a time works). The system is a Sun W2100z with 12 GB of ram, and
R segfaults using only around 360 MB of ram. I can include MySQL output fed to
the script on request, but it's usually for failure data around a max of 1,000
data points in the "failureQuery", and less than 30,000 for "usageQuery". I can
generate a core if desired too.

 begin traceback
--
s> source("SysVUserTime.R")
Loading required package: DBI

 *** caught segfault ***
address f9, cause 'memory not mapped'

Traceback:
 1: axis(side = side, at = at, labels = labels, ...)
 2: Axis.default(...)
 3: Axis(...)
 4: localAxis(x, side = 1, ...)
 5: plot.default(g$fit, g$res, xlab = "Fitted", ylab = "Residuals")
 6: plot(g$fit, g$res, xlab = "Fitted", ylab = "Residuals")
 7: eval.with.vis(expr, envir, enclos)
 8: eval.with.vis(ei, envir)
 9: source("SysVUserTime.R")

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection: 3
- end traceback
---

 begin script
-
#Connects to database
library(RMySQL)
library(chron)

CLAY_CLASS<-TRUE
PIE_CHARTS<-FALSE
BOXPLOTS<-TRUE
PLOTTING<-TRUE
OUTPUT_TEXT<-FALSE
ACF_PLOT<-TRUE
query_dates<-c("Year","Quarter","Month","Week")

oldpar <- par(no.readonly = TRUE)
drv <- dbDriver("MySQL")
con <- dbConnect(drv, user="macs370",dbname="lanl",password="macs370")
systems<-c("s8_usage_clean","s15_usage_clean","s16_usage_clean","s23_usage_clean","s20_usage_node_num_cpu")
systemNum<-c("8","15","16","23","20")

# Query for each system
for (iter in 1:length(systems)) {
#for (iter in 5:5) {
rm(dat,res,IQR_Stats,userStatTimes,cors,data)
if(OUTPUT_TEXT!=TRUE)
{ 
sink(paste("/export/MACS370_project/Image/SysVUserTime/CorrelationsSys",systemNum[iter],".TXT",sep=""))
}
if(PIE_CHARTS==TRUE) {
for (iter in 1:length(systems)) {
X11()
res<- dbSendQuery(con, paste("SELECT
SUM(cpu_seconds_user)/SUM(total_time), SUM(cpu_seconds_system)/SUM(total_time)
FROM ",systems[iter],";",sep=""))
dat<- fetch(res,n=-1)
data<-rbind(dat[,1],dat[,2])
pie(data,labels=c("User","System"),main=paste("System
vs. User Time for System ",systemNum[iter],"by",QUERY_DATE,sep=""))
}
}

# Query for each date segmentation
for(k in 1:length(query_dates)) {
#for(k in 4:4) {
#for(k in 2:2) {
QUERY_DATE<-query_dates[k]

userTime<-NULL
failures<-NULL

# Date Clamp Limits Us To The Middle 80% Of All Data
usageDateClamp<-paste(" WHERE FROM_UNIXTIME(submit_time) >= (SELECT ",
"FROM_UNIXTIME(MIN(submit_time)) + INTERVAL 0.10*",
"DATEDIFF(MAX(FROM_UNIXTIME(submit_time)),MIN(FROM_UNIXTIME(",
"submit_time))) DAY FROM ",systems[iter],") AND
FROM_UNIXTIME(",
"submit_time) <= (SELECT FROM_UNIXTIME(MAX(submit_time)) - ",
"INTERVAL 0.10*DATEDIFF(MAX(FROM_UNIXTIME(submit_time)),MIN(",
"FROM_UNIXTIME(submit_time))) DAY FROM ",systems[iter],") ",
sep="")
failureDateClamp<-paste(" AND prob_start_date >= (SELECT ",
"FROM_UNIXTIME(MIN(submit_time)) + INTERVAL 0.10*",
"DATEDIFF(MAX(FROM_UNIXTIME(submit_time)),MIN(FROM_UNIXTIME(",
"submit_time))) DAY FROM ",systems[iter],") ",
"AND prob_start_date <= (SELECT ",
"FROM_UNIXTIME(MAX(submit_time)) - INTERVAL 0.10*",
"DATEDIFF(MAX(FROM_UNIXTIME(submit_time)),MIN(FROM_UNIXTIME(",
"submit_time))) DAY FROM ",systems[iter],") ",sep="")

if(QUERY_DATE=="Year") {
usageAVGQuery<-paste("SELECT
STR_TO_DATE(CONCAT(YEAR(FROM_UNIXTIME(dispatch_time)),'-01-01'),'%Y-%m-%d') AS
date, AVG(cpu_seconds_user/total_time) AS time, AVG(num_cpus) AS AVG_CPUs,
AVG(dispatch_time-end_time) AS AVG_job_length FROM
",systems[iter],usageDateClamp,"GROUP BY date;",sep="")
usageQuery<-paste("SELECT
STR_TO_DATE(CONCAT(YEAR(FROM_UNIXTIME(dispatch_time)),'-01-01'),'%Y-%m-%d') AS
date, cpu_seconds_user/total_time AS time FROM ",systems[iter],"
",usageDateClamp,";",sep="")
if(CLAY_CLASS=="TRUE") {
failureQuery<-paste("SELECT
DISTINCT(STR_TO_DATE(CONCAT(YEAR(FROM_UNIXTIME(dispatch_time)),'-01-01'),'%Y-%m-%d'))
AS date, if(tbl.probs is NULL,0,tbl.probs) FROM ",systems[iter]," LEFT JOIN
(SELECT SUM(if(clay_class

[Rd] How to preserve data across function calls in a library package

2007-07-10 Thread Saptarshi Guha
Hi,
I am writing an R package with two functions in C++. So far  
everything works.
Now, i would like to write a third function which would use a pointer 
(it is a pointer to a class object) created by first function.
I tried placing this pointer outside of the function definitions  
(i.e to make it global) but when called in the 3rd function i get
>*** caught bus error ***
address 0x0, cause 'invalid alignment'"

I tried Callocing it in the 1st function but to no avail. Here is a  
quick summary. When foo is called (through do_foo, **after** having  
called do_kNN_e) i get the aforementioned error.
Can anyone provide some pointers (no pun intended) on this?

Thanks
Saptarshi

ANN* book;
int* foot;

void foo(void){
   Rprintf("many times\n");
   Rprintf("%p\n",book);
   Rprintf("%p\n",foot);
}

SEXP
kNN_e(SEXP data, SEXP Nrow, SEXP Ncol,SEXP K,SEXP Eps)
{
   int nrow=asInteger(Nrow);
   int ncol=asInteger(Ncol);
   int k=asInteger(K);
   double eps=asReal(Eps);

   SEXP ans,distance;
   SEXP retlist;
   PROTECT(ans=allocMatrix(INTSXP,nrow,k)); //The 2nd argument gives  
the number of rows, and the last the number of cols see http://cran.r- 
project.org/doc/manuals/R-exts.html
   PROTECT(distance=allocMatrix(REALSXP,nrow,k));
   ANNpointArray datapoints;
   ANNpoint qpoint;
   ANNkd_tree* kdTree;
   book=Calloc(1,ANN*);
   foot=Calloc(1,int);
   book=kdTree;
  *foot=10;

  ...
}

extern "C" {
   void do_foo(void){
 foo();
   }

SEXP
do_kNN_e(SEXP data, SEXP Nrow, SEXP Ncol,SEXP k,SEXP eps)
{
   return kNN_e(data,Nrow, Ncol,
 k,eps);

}



[[alternative HTML version deleted]]

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


Re: [Rd] [R] How to preserve data across function calls in a library package

2007-07-10 Thread Saptarshi Guha
Hi,
Some progress: I am using
SEXP retty;
book=Calloc(1,int);
*book=10;
PROTECT(retty=R_MakeExternalPtr(book,R_NilValue,R_NilValue));

then UNPROTECTING and returning retty.

In a another function,
foo(SEXP s){
 int* f=(int *)R_ExternalPtrAddr(p);
 Rprintf("many times %d\n",*f); 
}

When called do_foo(p) where do_foo calls foo and p is the pointer  
returned by the former code snippet, the Rprintf successfully prints  
the correct value but subsequently crashes
*** caught bus error ***
address 0x0, cause 'invalid alignment'.

I can't figure out why... I would appreciate any advice provided.
Rgds
Saptarshi




On Jul 10, 2007, at 11:41 AM, Saptarshi Guha wrote:

> Hi,
>   I am writing an R package with two functions in C++. So far
> everything works.
>   Now, i would like to write a third function which would use a pointer
> (it is a pointer to a class object) created by first function.
>   I tried placing this pointer outside of the function definitions
> (i.e to make it global) but when called in the 3rd function i get
>>   *** caught bus error ***
> address 0x0, cause 'invalid alignment'"
>
>   I tried Callocing it in the 1st function but to no avail. Here is a
> quick summary. When foo is called (through do_foo, **after** having
> called do_kNN_e) i get the aforementioned error.
>   Can anyone provide some pointers (no pun intended) on this?
>
>   Thanks
>   Saptarshi
>
> ANN* book;
> int* foot;
>
> void foo(void){
>Rprintf("many times\n");
>Rprintf("%p\n",book);
>Rprintf("%p\n",foot);
> }
>
> SEXP
> kNN_e(SEXP data, SEXP Nrow, SEXP Ncol,SEXP K,SEXP Eps)
> {
>int nrow=asInteger(Nrow);
>int ncol=asInteger(Ncol);
>int k=asInteger(K);
>double eps=asReal(Eps);
>
>SEXP ans,distance;
>SEXP retlist;
>PROTECT(ans=allocMatrix(INTSXP,nrow,k)); //The 2nd argument gives
> the number of rows, and the last the number of cols see http://cran.r-
> project.org/doc/manuals/R-exts.html
>PROTECT(distance=allocMatrix(REALSXP,nrow,k));
>ANNpointArray datapoints;
>ANNpoint qpoint;
>ANNkd_tree* kdTree;
>book=Calloc(1,ANN*);
>foot=Calloc(1,int);
>book=kdTree;
>   *foot=10;
>
>   ...
> }
>
> extern "C" {
>void do_foo(void){
>  foo();
>}
>
> SEXP
> do_kNN_e(SEXP data, SEXP Nrow, SEXP Ncol,SEXP k,SEXP eps)
> {
>return kNN_e(data,Nrow, Ncol,
>k,eps);
>
> }
>
>
>
>   [[alternative HTML version deleted]]
>
> __
> [EMAIL PROTECTED] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

Saptarshi Guha | [EMAIL PROTECTED] | http://www.stat.purdue.edu/~sguha
Would you people stop playing these stupid games?!?!?

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


Re: [Rd] BLAS / LAPACK version information from within R-session?

2007-07-10 Thread Jason Riedy
And Brian Ripley writes:
> I know of no way to ask a BLAS dynamic library what version it
> is.

Tinkering with the BLAS interface hasn't fared so well, but
LAPACK 3.1 added an ILAVER subroutine that returns the major,
minor, and patch level versions for LAPACK itself.

>> An obvious application could be safety-checks for packages
>> like Matrix and quantreg at load / attach - time.
>
> Why should that be needed?

To warn of bugs in specific LAPACK versions, perhaps.  I know I
let a couple of embarassing typos merge into 3.1.0 with the
eigenvalue drivers.  The ones I know of so far only affect
performance, but there may be another that leads to an unreported
error.  Looks like R makes DSYEVR available through eigen.R, so
it's affected.  Sorry.

And I know prior LAPACK versions have some painful error cases.
They seem to impact few people, so having the LAPACK version in
related bug reports may help remove those causes.

>> Perhaps this information may even be included into the output
>> of R.Version() :-) ?
>
> I can think of more worthy candidates, e.g. the compilers used
> to build R, and for Linux something more precise about the
> distro used.

Alas, yes, those could be very useful with the resurgence of
funny arithmetics.

Jason

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


[Rd] Getting param names of primitives

2007-07-10 Thread miguel manese
Hi,

In the latest R this does not work anymore

args <- formals(log)

because log is primitive. Is there any other way to get the argument
list? I just need the name of the parameter to display some error
message about it. I have looked at args() but I can't find anything to
extract the argument names from it.

Thanks,
M. Manese

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


Re: [Rd] Getting param names of primitives

2007-07-10 Thread Prof Brian Ripley
> formals(args(log))
$x


$base
exp(1)

gives what formals(log) used to.

On Wed, 11 Jul 2007, miguel manese wrote:

> Hi,
>
> In the latest R this does not work anymore
>
> args <- formals(log)
>
> because log is primitive. Is there any other way to get the argument
> list? I just need the name of the parameter to display some error
> message about it. I have looked at args() but I can't find anything to
> extract the argument names from it.
>
> Thanks,
> M. Manese

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


Re: [Rd] Getting param names of primitives

2007-07-10 Thread miguel manese
Thanks! Worked like a charm.

Regards,
M. Manese

On 7/11/07, Prof Brian Ripley <[EMAIL PROTECTED]> wrote:
> > formals(args(log))
> $x
>
>
> $base
> exp(1)
>
> gives what formals(log) used to.
>
> On Wed, 11 Jul 2007, miguel manese wrote:
>
> > Hi,
> >
> > In the latest R this does not work anymore
> >
> > args <- formals(log)
> >
> > because log is primitive. Is there any other way to get the argument
> > list? I just need the name of the parameter to display some error
> > message about it. I have looked at args() but I can't find anything to
> > extract the argument names from it.
> >
> > Thanks,
> > M. Manese
>
> --
> Brian D. Ripley,  [EMAIL PROTECTED]
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford, Tel:  +44 1865 272861 (self)
> 1 South Parks Road, +44 1865 272866 (PA)
> Oxford OX1 3TG, UKFax:  +44 1865 272595
>

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