From hb at stat.berkeley.edu  Sun Feb 21 10:40:08 2010
From: hb at stat.berkeley.edu (Henrik Bengtsson)
Date: Sun, 21 Feb 2010 10:40:08 +0100
Subject: [Rd] system.time provides inaccurate sys.child (PR#14210)
In-Reply-To: <20100210134511.4BDA32830315@mail.pubhealth.ku.dk>
References: <20100210134511.4BDA32830315@mail.pubhealth.ku.dk>
Message-ID: <59d7961d1002210140m10d0d88ei18f0ea7e5aa76219@mail.gmail.com>

FYI,

you're much more likely to get a response/see actions on this if you
report issues using the most recent stable version (R v2.10.1) and/or
even the developers version (R v2.11.0).  You're current version is,
as you see, more than 2 years old.  It is likely that the threshold to
compare the code of your version with the latest one etc is to large
for someone to be bothered.

/Henrik

On Wed, Feb 10, 2010 at 2:45 PM,  <manuel.lopez-ibanez at ulb.ac.be> wrote:
> Full_Name: Manuel L?pez-Ib??ez
> Version: R version 2.6.2 (2008-02-08)
> OS: linux-gnu
> Submission from: (NULL) (164.15.10.156)
>
>
> This is only relevant for CPU intensive child processes. Otherwise, the problem
> is not obvious.
>
> Therefore, we need a CPU intensive program like this one:
>
> /************************************/
> /*** Compile with: gcc -o timer-test -O0 timer-test.c -lm */
> #include <stdio.h>
> #include <stdlib.h>
> #include <math.h>
>
> double alpha, beta;
> int size = 1000;
>
> #define WORK_create_matrix(TYPEOFMATRIX) ? ? ? ? ? ? ? ?\
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\
> TYPEOFMATRIX ** m_create_##TYPEOFMATRIX##_matrix ( ? ? ?\
> int dim1, int dim2, int line, const char*file) ? ? ? ? ?\
> { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? \
> ? ?TYPEOFMATRIX **p; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? \
> ? ?int i; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\
> ? ?p = malloc (sizeof(TYPEOFMATRIX) * dim1 * dim2 ? ? ?\
> ? ? ? ? ? ? ? ?+ sizeof(TYPEOFMATRIX *) * dim1 ); ? ? ?\
> ? ?if (p == NULL) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\
> ? ? ? ?fprintf(stderr, "cannot create " #TYPEOFMATRIX ?\
> ? ? ? ? ? ? ? ?" matrix of size (%d x %d): " ? ? ? ? ? \
> ? ? ? ? ? ? ? ?"see line %d of file %s\n", ? ? ? ? ? ? \
> ? ? ? ? ? ? ? ?dim1, dim2, line, file); ? ? ? ? ? ? ? ?\
> ? ? ? ?exit(1); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\
> ? ?} ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? \
> ? ?for (i = 0; i < dim1; i++) ? ? ? ? ? ? ? ? ? ? ? ? ?\
> ? ? ? ?p[i] = (TYPEOFMATRIX *) (p + dim1) + i * dim2; ?\
> ? ?return p; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? \
> }
>
> WORK_create_matrix(int)
> WORK_create_matrix(double)
> #undef WORK_create_matrix
> #define create_double_matrix(dim1,dim2)\
> ? ?m_create_double_matrix(dim1,dim2,__LINE__,__FILE__)
>
>
> int main(int argc, char *argv[])
> {
> ? ?double **matrix1 = create_double_matrix(size, size);
> ? ?double **matrix2 = create_double_matrix(size, size);
> ? ?int iterations = 0;
> ? ?int i,j;
> ? ?double iter_limit = 100;
> ? ?alpha = rand();
> ? ?beta = rand();
>
> ? ?while (iterations < iter_limit) {
> ? ? ? ?for (i = 0; i < size; i++) {
> ? ? ? ? ? ?for (j = 0; j < size; j++) {
> ? ? ? ? ? ? ? ?if (i == j) continue;
> ? ? ? ? ? ? ? ?matrix2[i][j] = pow(matrix1[i][j], alpha)
> ? ? ? ? ? ? ? ? ? ?* pow(matrix2[j][i], beta);
> ? ? ? ? ? ? ? ?matrix1[j][i] = matrix2[i][j];
> ? ? ? ? ? ?}
> ? ? ? ?}
> ? ? ? ?iterations++;
> ? ?}
>
> ? ?printf("Iterations = %d\n", iterations);
> ? ?return 0;
> }
> /************************************/
>
> Then in R evaluate:
>
>> print.default (system.time (system(paste ("time", "bash -c './timer-test 100 >
> /dev/null'"))))
> 10.77user 0.02system 0:10.81elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
> 0inputs+0outputs (0major+4574minor)pagefaults 0swaps
> ?user.self ? sys.self ? ?elapsed user.child ?sys.child
> ? ? 0.000 ? ? ?0.000 ? ? 10.818 ? ? 10.777 ? ? 10.777
> attr(,"class")
> [1] "proc_time"
>
> Expected: the sys.child time should be 0.02.
>
>> version
> ? ? ? ? ? ? ? _
> platform ? ? ? i486-pc-linux-gnu
> arch ? ? ? ? ? i486
> os ? ? ? ? ? ? linux-gnu
> system ? ? ? ? i486, linux-gnu
> status
> major ? ? ? ? ?2
> minor ? ? ? ? ?6.2
> year ? ? ? ? ? 2008
> month ? ? ? ? ?02
> day ? ? ? ? ? ?08
> svn rev ? ? ? ?44383
> language ? ? ? R
> version.string R version 2.6.2 (2008-02-08)
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] system.time provides inaccurate sys.child (PR#14210)
Henrik Bengtsson