Intel MKL memory management and exceptions

Posted by Andrew on Stack Overflow See other posts from Stack Overflow or by Andrew
Published on 2010-03-11T05:58:46Z Indexed on 2010/03/17 6:01 UTC
Read the original article Hit count: 228

Filed under:
|
|

Hello everyone,

I am trying out Intel MKL and it appears that they have their own memory management (C-style).

They suggest using their MKL_malloc/MKL_free pairs for vectors and matrices and I do not know what is a good way to handle it. One of the reasons for that is that memory-alignment is recommended to be at least 16-byte and with these routines it is specified explicitly.

I used to rely on auto_ptr and boost::smart_ptr a lot to forget about memory clean-ups.

How can I write an exception-safe program with MKL memory management or should I just use regular auto_ptr's and not bother?

Thanks in advance.

EDIT http://software.intel.com/sites/products/documentation/hpc/mkl/win/index.htm

this link may explain why I brought up the question

UPDATE

I used an idea from the answer below for allocator. This is what I have now:

template <typename T, size_t TALIGN=16, size_t TBLOCK=4>
class aligned_allocator : public std::allocator<T>
{
public:
 pointer allocate(size_type n, const void *hint)
 {
  pointer p = NULL;
  size_t count = sizeof(T) * n;
  size_t count_left = count % TBLOCK;
  if( count_left != 0 ) count += TBLOCK - count_left;
  if ( !hint ) p = reinterpret_cast<pointer>(MKL_malloc (count,TALIGN));
  else   p = reinterpret_cast<pointer>(MKL_realloc((void*)hint,count,TALIGN));
  return p;
     } 
 void deallocate(pointer p, size_type n){ MKL_free(p); }
};

If anybody has any suggestions, feel free to make it better.

© Stack Overflow or respective owner

Related posts about intel-mkl

Related posts about c++