Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

short int or char in viRngUniform

dario_suarez
Beginner
468 Views

Hello,

I'm usign large array of very small random numbers, often between 0 and 10. This large arrays consume 4 bytes per entry (int), and I would like to know if there is a way for generating arrays of short int and chars to save memory.

Thanks in advance for your help,

Daro

0 Kudos
1 Solution
Sergey_M_Intel2
Employee
468 Views
Hello Dario,

Unfortunately there is no 8-bit or 16-bit variant of the uniform RNG in MKL. The only workaround that I see is to generate the data by portions as 32-bit integers and process those integers in a way you need. It will save the storage.

If for some reason youneed to store entire array of chars you still can generate it by blocks by converting each block into array of bytes, something like this:

#define N (1024*1000)

#define BLOCK_SIZE 1024

int block[BLOCK_SIZE];

char urng;

... //Create the random stream

for (i=0; i

{

// Generate block of 32-bit integers

viRndUniform(0, stream, BLOCK_SIZE, block, 0, 10);

for (j=0; j

{

urng[i+j] = (char)block;

}

}

... // Delete the random stream

That may help,

Regards,

Sergey

View solution in original post

0 Kudos
2 Replies
Sergey_M_Intel2
Employee
469 Views
Hello Dario,

Unfortunately there is no 8-bit or 16-bit variant of the uniform RNG in MKL. The only workaround that I see is to generate the data by portions as 32-bit integers and process those integers in a way you need. It will save the storage.

If for some reason youneed to store entire array of chars you still can generate it by blocks by converting each block into array of bytes, something like this:

#define N (1024*1000)

#define BLOCK_SIZE 1024

int block[BLOCK_SIZE];

char urng;

... //Create the random stream

for (i=0; i

{

// Generate block of 32-bit integers

viRndUniform(0, stream, BLOCK_SIZE, block, 0, 10);

for (j=0; j

{

urng[i+j] = (char)block;

}

}

... // Delete the random stream

That may help,

Regards,

Sergey

0 Kudos
dario_suarez
Beginner
468 Views

Hi Sergey,

Thanks. The idea of blocking seems very good. I'll implement it and see the effect on memory and performance.

Best regards,

Daro

0 Kudos
Reply