OpenMP signed int problem

Started by
3 comments, last by Misery 12 years ago
Hello,

I have a problem which I really have no idea how to solve.
I need to create a huge array in C++ containing lots of doubles. Therefore I use std::size_t type to store the size etc.
But as I said, the array is big and to make my program faster i wanted to use OpenMP in such manner for example:


#pragma omp parallel for default(none) shared(N,Data) reduction(+:s)
for (size_t i=0;i<N;i++) s+=Data;


but I get the error saying that openMP requires signed int to run for loop.
How do I workaround it?

Thanks in advance,
Regards
Advertisement
Later versions of OpenMP relaxes this requirement if I remember correct. But is your array really large enough so that you cannot use a signed loop index? You can use a singed 64-bit loop index if you really use an array with more than 2 billion elements.
Thanks for the answer.
I really need to use huge arrays, as it will store sparse arrays for engineering problems in triplet format. And such arrays might become really big. And on the other hand it would be silly to cancel possibility to use bigger arrays if I can use them on x64 OS due to 2^64 memory access.

Because of good CUDA support I am using VS2008 on windows, is there any way to use newer OpenMP version than this delivered with this IDE?
OpenMP on gcc 4.6.1 doesn't seem to have a problem with this.

How big is one of these triplets? Chances are it will be something like 16 bytes, which means that an array of 2^31 of them uses 32 GB of memory. Are you sure your arrays can be that large?

You can try using a 64-bit signed integer type and see if your compiler likes that better.
Well, I can use shared memory small HPC server with 32 GB of memory. It isn't anything unusual at the moment to use more than 4GB of RAM :]
Therefore I don't want to be limited by 4GB of address on 32 bit machines.
Anyway I write my code to compile on both GCC and MSVC, so switching to GCC if necessary won't be a problem. I'll just put this in DLL and make a plugin of my array manager and use it as external service from MSVC compiled code. I want to use MSVC because of CUDA support - i mean ready to use templates etc.
But getting back to subject:
If I want to go trough the whole array (requiring size_t to order elements) it doesn't matter if my loop counter is signed or unsigned. So maybe I could begin loop at i=min_int_value and finish at i=min_int_value+N.

signed long long min_int_v=limits.h<signed long long>.min() //or sth like that ;)
DataType *p=Data+min_int_v;
#pragma omp parallel for default(none) shared(N,p,min_int_v) reduction(+:s)
for (signed long long i=min_int_v;i<min_int_v+N;i++) s+=p;

But if N is unsigned long long will that work fine? Will adding

signed long long aNumber=min_int_v+ unsignedLongN;


work fine?

This topic is closed to new replies.

Advertisement