Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Petros_Mamales
Beginner
88 Views

i_malloc_dll.h

Hi,
According to the user's manual, I should include the above file to set the allocation functions used by mkl.
a) this file does not exist in the distribution I have (MKL 10.2.4.032) !!
b) even if I go for the static libraries file (i_malloc.h) and try to assign the tbb malloc/free (scallable_..)
the compiler complains that they are already defined (the function pointers). What am I doing wrong??
The only example in the manual, sets the pointers w/in some main.
What if I want to promote it to my allocation "policy" in a library? (I assumed it to be the same if in global namespace, correct?)
Thank you in advance for your help.
Petros

PS1: Usng win7, mkl 10.2, vs2010 (ms compiler), tbb4.
PS2: It might be a good idea if different products from intel hpc effort had the same "allocators". For Example IPP does not even provided for such an overwritting mechanism. Just saying ;-))
0 Kudos
9 Replies
barragan_villanueva_
Valued Contributor I
88 Views

Hi,

MKL doc suggests to usethe samei_malloc.h but with different assignments on Windows.
For static case:

i_malloc = my_malloc;

i_calloc = my_calloc;

i_realloc = my_realloc;

i_free = my_free;

but for dynamic one - it should be:

i_malloc_dll = my_malloc;

i_calloc_dll = my_calloc;

i_realloc_dll = my_realloc;

i_free_dll = my_free;

Petros_Mamales
Beginner
88 Views

Hi Victor,
Thank you for your response.
hat about the compilation error?
Here is what I get:

1>c:_petros_otcsrcotclibexternalmklmemory.h(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:_petros_otcsrcotclibexternalmklmemory.h(13): error C2373: 'i_malloc' : redefinition; different type modifiers
1> c:program filesintelmkl10.2.4.032includei_malloc.h(127) : see declaration of 'i_malloc'
1>c:_petros_otcsrcotclibexternalmklmemory.h(13): error C2065: 'scallabe_malloc' : undeclared identifier
etc..


for this piece of code:


#include
//OTC choices:
//#define OTC_USE_MKL_ALLOCATORS
#define OTC_USE_TBB_ALLOCATORS
#define OTC_USE_TBB_ALLOCATORS_FOR_MKL

#if !defined(OTC_USE_MKL_ALLOCATORS)
#if defined(OTC_USE_TBB_ALLOCATORS_FOR_MKL)
#include "tbb/scalable_allocator.h"
i_malloc = scallabe_malloc;
i_calloc = scallabe_calloc;
i_realloc = scallabe_realloc;
i_free = scallabe_free;
#ifdef _WIN32
i_malloc_dll = scallabe_malloc;
i_calloc_dll = scallabe_calloc;
i_realloc_dll = scallabe_realloc;
i_free_dll = scallabe_free;
#endif

#else
i_malloc_dll = malloc;
i_calloc_dll = calloc;
i_realloc_dll = realloc;
i_free_dll = free;
#endif
#endif

Thank you for your hep,
Petros
barragan_villanueva_
Valued Contributor I
88 Views

Petros,

This source is not complete so first three errors are not clear for me.
Maybe you need some self-contained file for reassigning TBB-allocator instead of MKL memory manager?
But please fix a typo: TBB-functions are to be with names scalable_* not scallabe_*
Petros_Mamales
Beginner
88 Views

Hi Victor,
Thank you for the response.
SO I consolidated a few things and found out that I need to declare things like:

i_malloc_t i_malloc = scalable_malloc;
etc..
However, this does not work for the dll version of the functions.
Here is a consolidated main:

#include
#include "tbb/scalable_allocator.h"

i_malloc_t i_malloc = scalable_malloc;
i_calloc_t i_calloc = scalable_calloc;
i_realloc_t i_realloc = scalable_realloc;
i_free_t i_free = scalable_free;

i_malloc_t i_malloc_dll = scalable_malloc;
i_calloc_t i_calloc_dll = scalable_calloc;
i_realloc_t i_realloc_dll = scalable_realloc;
i_free_t i_free_dll = scalable_free;

//os
#include

//std
#include
using std::string;
#include
using std::stringstream;
#include
using std::cout;
using std::endl;
//boost
#include
using boost::array;

#include
#include

/*---------------------------------------------------
Class to encapsulate mkl's:
-memory choices
-array boundaries
-2-d array lda
-thread management:

The ppc macros:
OTC_USE_MKL_ALLOCATORS
OTC_USE_TBB_ALLOCATORS
OTC_USE_TBB_ALLOCATORS_FOR_MKL
act with the following precedence rules:
If OTC_USE_MKL_ALLOCATORS is defined
the mkl_malloc/free are used.
If not and the other two macros are defined
then the tbb scallable_malloc/free will be used.
O/wise the OS malloc/free is employed.
---------------------------------------------------*/

class MKL{
public:
static const size_t ARRAY_BOUNDARY_IN_BYTES = 64;
static const size_t LDA_DIVISOR_IN_BYTES = 16;
static const size_t LDA_DIVISOR_IN_BYTES_FORBITTEN = 2048;

MKL(){
mkl_get_version(&version_);
}

~MKL()
{}

/*---------------------------------------------------
Version:
---------------------------------------------------*/
int majorVersion() const {
return version_.MajorVersion;
}
/*---------------------------------------------------
Memory:
---------------------------------------------------*/
// Functions to provide with mkl-compliant alloc/dealloc functionality.
template< typename _T >
static _T * allocate( const size_t size ){
return (_T*)(mkl_malloc( sizeof(_T)*size, ARRAY_BOUNDARY_IN_BYTES ));
}
template< typename _T >
static void deallocate( _T * ptr ){
mkl_free( (void*)ptr );
}
// freeing mkl-allocated memory:
static void freeAuxMemory(){
mkl_free_buffers();
}
static void freeAuxThreadMemory(){
mkl_thread_free_buffers();
}

private:
MKLVersion version_;
};

int main(){

MKL mkl;
cout << mkl.majorVersion() << endl;
}


with error msg:

1>Build started 11/2/2011 11:03:47 AM.
1>ClCompile:
1> main.cpp
1>c:\_petros\tests\mkl\mkl\main.cpp(9): warning C4273: 'i_malloc_dll' : inconsistent dll linkage
1> c:\program files\intel\mkl\10.2.4.032\include\i_malloc.h(115) : see previous definition of 'i_malloc_dll'
1>c:\_petros\tests\mkl\mkl\main.cpp(10): warning C4273: 'i_calloc_dll' : inconsistent dll linkage
1> c:\program files\intel\mkl\10.2.4.032\include\i_malloc.h(116) : see previous definition of 'i_calloc_dll'
1>c:\_petros\tests\mkl\mkl\main.cpp(11): warning C4273: 'i_realloc_dll' : inconsistent dll linkage
1> c:\program files\intel\mkl\10.2.4.032\include\i_malloc.h(117) : see previous definition of 'i_realloc_dll'
1>c:\_petros\tests\mkl\mkl\main.cpp(12): warning C4273: 'i_free_dll' : inconsistent dll linkage
1> c:\program files\intel\mkl\10.2.4.032\include\i_malloc.h(118) : see previous definition of 'i_free_dll'

having to do with the dllimport part of the declaration (?).
Any ideas for how to circumvent this?
Thank you fo your help,
Petros

barragan_villanueva_
Valued Contributor I
88 Views

Petros,

Please add makefile or used link line to reproduce your problem.
Petros_Mamales
Beginner
88 Views

Hi Victor,
There is nothing to add. It is a cpp file containing the entire compilation unit.
Just compile and link (actually you will not be able to even compile).
Thank you for your help,
Petros
barragan_villanueva_
Valued Contributor I
88 Views

Petros,

Warnings are because ofduplicate definitions :(
Lines4 - 12 should not be as declarations. Please move all i_malloc assignments to main.
Petros_Mamales
Beginner
88 Views

Hi Victor,
As I said, this is only an example! - please, refer to previous e-mail.
The goal here is to create a library which will be using mkl.
If this is to link against the mkl dll's how is it supposed to be done?
It seems to me there is no provision.
Given that LAPaCK is a central piece of code in a lot of packages, if one has to
link against te static libs, many problems will appear (from multiple definitions of
the same functions in the linking phase, in case some of these libs are compiled
together towards amn executable, to large footprints for individual builds).
What did the mkl designers have in mind?
Thank you for your help,
Petros
barragan_villanueva_
Valued Contributor I
88 Views

Petros,

It needs to have a correct example to see how it works.

If your goal is to create a separate library linked with MKL, then substituting MKL memory allocator is done differently. Maybe, the best variant for you is to create MKL custom (dynamic) library with additional object wheresubstituting i_malloc/i_free is done instead standard MKL settings.
Reply