[Trilinos-Users] Memory allocation problem in ML on win64

Charles Boivin charles.boivin at mayahtt.com
Thu Jul 7 06:53:13 MDT 2011


Is this the correct mailing list for ML problems/discussions? If not, let me know, I'll re-address the issue over there.

I think I have found a (serious?) problem in ML's memory allocation routine on win64. In
ML_memory_alloc() (file ml_memory.c), we have the following bit of code (I am assuming this is putting 'markers' at either end of the newly allocated memory block for error-checking purposes?)

***
      if ( i < MAX_MALLOC_LOG )
      {
         int_ptr    = (int *) var_ptr;
         (*int_ptr) = i + 1;
         int_ptr    = (int*) ((long) var_ptr + nchunks*ndouble - ndouble);
         (*int_ptr) = i + 1;
         ...
***

The problem is with the use of the (long) cast; on win64, a 'long' is a signed 32-bit integer. If var_ptr happens to reside in a memory region with an address >2GB, the cast to long will result in a negative integer, and mayhem will ensue (or in the particular case that I was tracking down, the code will simply crash on the following line).

I have noticed that ml_memory.h a 'ml_size_t' type is defined; it maps to size_t if defined, or to an int if not. Now, size_t on win64 is an unsigned 64-bit integer (which I assume is what we'd want), but I would think that mapping to int is definitely NOT what we want (at least for win64, it's not). Shouldn't unsigned integers be used? For my tests, I used 'unsigned long long', which is 64-bit, but I don't know if this would fly for all platforms.

By then replacing all (long) casts to (ml_size_t) in ml_memory.c, I was able to successfully use the ML_Preconditioner class for my problem. However, I have no idea if my modifications are appropriate for all platforms, or if they could cause other unseen problems in ML. What is clear, however, is that using (long) is problematic in this case.

Is it possible to get some advice on the best possible way to fix this?

Thank you.


Charles Boivin
MAYA Heat Transfer Technologies Ltd. 



More information about the Trilinos-Users mailing list