Hello! I have a curious problem, which I cannot solve. With my code I solve thousands of small linear programs with the package lpSolve automatically. But R crashes sometimes (~always, but always on different linear programs) in a strange way. For illustration, I tried to prepare a simple example, which shows the nature of the problem. The function aaa (see below) declares some constants (only in this special example) and in the end it solves the linear program. aaa(1) [,1] [,2] [1,] 0 0 [2,] 0 0 [3,] 0 0 [4,] 0 0 [5,] 52 0 [6,] 2 2 [7,] 0 0 [8,] 2 0 [9,] 0 0 [10,] 0 0 [11,] 0 0 [12,] 0 0 [13,] 54 0 Works fine. Now I make the *same* calculation, say 1000 times: aaa(1000) R (I have tried it with R2.0.1, 2.0.0, 1.9.1, 2.1.0dev) crashes completly - without warning and error message under Windows XP, Intel Pentium 3 with 256 MB RAM Under Linux SuSe 8.2 R (2.0.1) it crashes again, but in this case I get the following message: Calloc of 40004 bytes failed on line 114 of file lpkit.c ... Calloc of 80008 bytes failed on line 113 of file lpkit.c Error: cannot allocate vector of size 3 Kb Now I?m completly lost. Solving the linear program one time makes no problem. Solving it twice in the same way makes no problem either. Running the same calculation, say 1000 times, causes a crash. Why should there be a problem with memory? For any hint, I would be really happy. Thank you, Matthias ### ---------- function aaa ------------ aaa <- function(amount=1){ f.obj <- rep(0,33) w <- c(3,4,5,6,11,13,17,22,25,26,27,28,33) m <- matrix(c(0,0,1,1,1,1,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,0,0,0,0,1, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0, 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0, 0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0, 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,1 ),ncol=33,byrow=TRUE) f.dir <- c("=","=","=","=","=","=","=","=","=","=","=", "=","=","=","=","=","=","=","=","=","=","=","=", "=","=","=","=","=","=","=","=","=","=") f.rhs <- c(-52,0,54,0,2,0,0,0,0,0,0,0,0,0) lp.out <- matrix( ncol = 2, nrow = 13 ) for(ii in 1:amount){ # - simple iterate the same for( i in 1:13 ){ f.obj[ w[i] ] <- 1 lp.out[ i, 1 ] <- lp("min", f.obj, m, f.dir, f.rhs)$objval lp.out[ i, 2 ] <- lp("max", f.obj, m, f.dir, f.rhs)$objval f.obj <- rep( 0, 33 ) } } lp.out }
Unfortunately, I can't tell you how to solve this problem. However, I can confirm that this crash happens also on my machines (R 2.0.1 on Debian Sarge, AMD Athlon, 750 MHz, 256 MB RAM and R 2.0.0 on SuSE 9.0, Intel P4, 2.6 GHz, 512 MB RAM): R> aaa(1000) alloc of 80000 bytes failed alloc of 40000 bytes failed Speicherzugriffsfehler We had a model, which consists of 1000+ linear programs with each about 550 rows and 1100 columns (unipr.it/arpa/dipseq/EAAE/PR/Parallel 42b4_henningsen.pdf). On MS-Windows 2000/XP this model always crashed after some hundreds linear programs, but using Linux on the same machines it _never_ crashed. I really can't see the reason why our much larger programs worked, but these small programs let R crash. I hope that this information may help to solve this problem. Arne On Wednesday 30 March 2005 12:16, TEMPL Matthias wrote:> Hello! > > I have a curious problem, which I cannot solve. > With my code I solve thousands of small linear programs with the package > lpSolve automatically. But R crashes sometimes (~always, but always on > different linear programs) in a strange way. For illustration, I tried to > prepare a simple example, which shows the nature of the problem. The > function aaa (see below) declares some constants (only in this special > example) and in the end it solves the linear program. > > aaa(1) > [,1] [,2] > [1,] 0 0 > [2,] 0 0 > [3,] 0 0 > [4,] 0 0 > [5,] 52 0 > [6,] 2 2 > [7,] 0 0 > [8,] 2 0 > [9,] 0 0 > [10,] 0 0 > [11,] 0 0 > [12,] 0 0 > [13,] 54 0 > > Works fine. > Now I make the *same* calculation, say 1000 times: > aaa(1000) > R (I have tried it with R2.0.1, 2.0.0, 1.9.1, 2.1.0dev) crashes completly - > without warning and error message under Windows XP, Intel Pentium 3 with > 256 MB RAM Under Linux SuSe 8.2 R (2.0.1) it crashes again, but in this > case I get the following message: Calloc of 40004 bytes failed on line 114 > of file lpkit.c > ... > Calloc of 80008 bytes failed on line 113 of file lpkit.c > Error: cannot allocate vector of size 3 Kb > > Now I?m completly lost. Solving the linear program one time makes no > problem. Solving it twice in the same way makes no problem either. Running > the same calculation, say 1000 times, causes a crash. Why should there be a > problem with memory? > > For any hint, I would be really happy. > Thank you, > Matthias > > > ### ---------- function aaa ------------ > > aaa <- function(amount=1){ > f.obj <- rep(0,33) > > w <- c(3,4,5,6,11,13,17,22,25,26,27,28,33) > > m <- > matrix(c(0,0,1,1,1,1,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 >, > > > 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0, > > > 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,0,0,0,0,1, > > > 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, > > > 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, > > > 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0, > > > 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0, > > > 0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0, > > > 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0, > > > 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, > > > 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, > > > 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, > > > 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, > > > 0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,1 > > ),ncol=33,byrow=TRUE) > > f.dir <- c("=","=","=","=","=","=","=","=","=","=","=", > "=","=","=","=","=","=","=","=","=","=","=","=", > "=","=","=","=","=","=","=","=","=","=") > > f.rhs <- c(-52,0,54,0,2,0,0,0,0,0,0,0,0,0) > > lp.out <- matrix( ncol = 2, nrow = 13 ) > > for(ii in 1:amount){ # - simple iterate the same > > for( i in 1:13 ){ > > f.obj[ w[i] ] <- 1 > > lp.out[ i, 1 ] <- lp("min", f.obj, m, f.dir, f.rhs)$objval > > lp.out[ i, 2 ] <- lp("max", f.obj, m, f.dir, f.rhs)$objval > > f.obj <- rep( 0, 33 ) > > } > > } > lp.out > > } > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > R-project.org/posting-guide.html-- Arne Henningsen Department of Agricultural Economics University of Kiel Olshausenstr. 40 D-24098 Kiel (Germany) Tel: +49-431-880 4445 Fax: +49-431-880 1397 ahenningsen at agric-econ.uni-kiel.de uni-kiel.de/agrarpol/ahenningsen