Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7944 Discussions

_mm_malloc problems with large array size (>2Gb)

morganpbrown
Beginner
547 Views
Hello,

I need _mm_malloc() to allocate large arrays (>2Gb). However, I seem to have problems. I have attached a simple program in which I declare a size_t array dimension of 4E9 elements. I can malloc() without problem, but _mm_malloc() segfaults on execution. Here is the program:
int main(int argn, char** args) {
float *a;
size_t k = 4000000000;
long long i;

a = malloc(k);
for( i=0; i = 1.0*i; }
free(a);

a = (void *) _mm_malloc( k, 16 );
for( i=0; i = 1.0*i; }
_mm_free(a);

exit(0);
}

Interestingly, the compiler warns me when I try to _mm_malloc(). It seems that my size_t is being truncated to 32-bit int(???).
remark #1682: implicit conversion of a 64-bit integral type to a smaller integral type (potential portability problem)
a = (void *) _mm_malloc( k, 16 );
^
Environment:
  • Machine: 64-bit Opteron, 8Gb memory
  • Compiler: icc 9.0

Thanks in advance,
Morgan Brown

0 Kudos
2 Replies
TimP
Honored Contributor III
547 Views
If you are running the 64-bit compiler, you needn't be using _mm_malloc(). glibc malloc() will give 16-byte alignment by default (at least when used with correct headers and paths). _mm_malloc() has always posed portability problems; I don't know why they aren't addressed, at least for Intel compilers. You could post an issue on premier.intel.com, after correcting your sample, if you think an improvement would help you.
0 Kudos
morganpbrown
Beginner
547 Views
Thanks, Tim. That's all I needed to know to recommend ditching _mm_malloc().

Morgan

0 Kudos
Reply