Sign in to follow this  
Misery

OpenMP signed int problem

Recommended Posts

Misery    354
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:

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

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

Thanks in advance,
Regards

Share this post


Link to post
Share on other sites
Brother Bob    10344
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.

Share this post


Link to post
Share on other sites
Misery    354
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?

Share this post


Link to post
Share on other sites
alvaro    21246
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.

Share this post


Link to post
Share on other sites
Misery    354
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.
[code]
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[i];
[/code]
But if N is unsigned long long will that work fine? Will adding
[code]
signed long long aNumber=min_int_v+ unsignedLongN;
[/code]

work fine?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this