David
2010-Oct-13 13:46 UTC
[R] "Memory not mapped" when using .C, problem in Mac but not in Linux
Hello, I am aware this may be an obscure problem difficult to advice about, but just in case... I am calling a C function from R on an iMac (almost shining: bought by my institution this year) and gives a "memory not mapped" error. Nevertheless, exactly the same code runs without problem in a powerful computer using SuSE Linux, but also on my laptop of 2007, 32 bits, 2 GB RAM, running Ubuntu. My supervisor says that he can run my code on his iMac (a bit older than mine) without problem. I have upgraded to the latest version of R, and I have tried compiling the C code with the latest version of gcc (obtained from MacPorts), but the error persists. Any ideas? Thank you very much in advance, David Can you please Cc to me any replies, just in case I may miss any of them among the whole amount of emails :-) ? [[alternative HTML version deleted]]
William Dunlap
2010-Oct-13 16:54 UTC
[R] "Memory not mapped" when using .C, problem in Mac but not in Linux
This often happens when your C code uses memory that it did not allocate, particularly when it reads or writes just a little beyond the end of a memory block. On some platforms or if you are lucky there is unused memory between blocks of allocated memory and you don't see a problem. Other machines may pack allocated memory blocks more tightly and writing off the end of an array corrupts another array, leading to the program crashing. (Or reading off the end of an array may pick up data from the next array, which leads to similar crashes later on.) You may also be reading memory which has never been written to, hence you are using random data, which could corrupt things. Use a program like valgrind (on Linux, free) or Purify (on various platforms, but pricy) to detect memory misuse in C/C++ code. As long as your code isn't #ifdef'ed for various platforms, you can use valgrind to detect and fix memory misuse on Linux and you will find that overt problems on other platforms will go away. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of David > Sent: Wednesday, October 13, 2010 6:47 AM > To: r-help at r-project.org > Subject: [R] "Memory not mapped" when using .C,problem in Mac > but not in Linux > > Hello, > > I am aware this may be an obscure problem difficult to advice > about, but > just in case... I am calling a C function from R on an iMac > (almost shining: > bought by my institution this year) and gives a "memory not > mapped" error. > > Nevertheless, exactly the same code runs without problem in a powerful > computer using SuSE Linux, but also on my laptop of 2007, 32 > bits, 2 GB RAM, > running Ubuntu. My supervisor says that he can run my code on > his iMac (a > bit older than mine) without problem. > > I have upgraded to the latest version of R, and I have tried > compiling the C > code with the latest version of gcc (obtained from MacPorts), > but the error > persists. > > Any ideas? > > Thank you very much in advance, > > David > Can you please Cc to me any replies, just in case I may miss > any of them > among the whole amount of emails :-) ? > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org 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. >
Berend Hasselman
2010-Oct-13 18:39 UTC
[R] "Memory not mapped" when using .C, problem in Mac but not in Linux
- which version of Mac OS X? - Which version of R? (version, architecture) - Officially provided R or compiled by you? Official R is compiled with Apple gcc. - if R was compiled with Apple compiler, who knows what can happen if you link with code compiled with a non Apple gcc? - if the code runs ok on your supervisors iMac: did he use Apple compiler? if so I wouldn't be surprised if your Macports compiler is a possible cause of your troubles. - on 64bit Mac OS X long int is 64bits and int is 32bits; on 32bit Mac OSX both are 32 bits. /Berend -- View this message in context: http://r.789695.n4.nabble.com/Memory-not-mapped-when-using-C-problem-in-Mac-but-not-in-Linux-tp2993689p2994220.html Sent from the R help mailing list archive at Nabble.com.
David
2010-Oct-14 11:54 UTC
[R] "Memory not mapped" when using .C, problem in Mac but not in Linux
Thank you, William and Berend, for your thorough replies. I have still the habit of setting "long int" variables because, when I first learnt C, the manual said that "int" could be up to around 3.2e4. But I suppose that, in systems from 32 bits, an "int" number can be much larger, isn't it? - which version of Mac OS X?>10.6.4> - Which version of R? (version, architecture) >The version is 2.11.1 (although I had the same problem with the previous version). I downloaded the binary for Mac from r-project. In the Applications menu, I can see "R" and "R64". Nevertheless, I start R in the command line: like this, I suppose it is the 64 bits version which starts, isn't it?> - Officially provided R or compiled by you? Official R is compiled with > Apple gcc. >The official one.> - if R was compiled with Apple compiler, who knows what can happen if you > link with code compiled with a non Apple gcc? >It is the official. Nevertheless, my code C for R works in Linux whether I compile my C functions with gcc or with icc.> - if the code runs ok on your supervisors iMac: did he use Apple compiler? >I do not think he compiled it himself. For the architecture, he does not remember well, he has said that he thinks that he is using a version of R that was compiled in 32 bits.> if so I wouldn't be surprised if your Macports compiler is a possible cause > of your troubles. >I do not think so. Both R and the "default" gcc did not come from Macports. The "default" gcc came with Xcode in the extras' cd (by the way, how can gcc in Mac be upgraded?).> - on 64bit Mac OS X long int is 64bits and int is 32bits; on 32bit Mac OSX > both are 32 bits. >Thank you. As I said, chaging from "unsigned long int" to "int" seemed to solve the problem. David Can you please Cc to me any replies, just in case I may miss any of them among the whole amount of emails :-) ? [[alternative HTML version deleted]]
Apparently Analagous Threads
- convert command not found in movie3d (rgl package) in Mac OS X
- iMAC does not shutdown
- iMAC does not shutdown
- [Bug 13266] New: Writing of files to Apple's new "AP" controller model SSD's takes 4x longer.
- Problem with text entry fields (Mac OS X Snow leopard)