Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for more than 2^32 elements? #2

Open
JustinChu opened this issue Apr 6, 2018 · 5 comments
Open

Support for more than 2^32 elements? #2

JustinChu opened this issue Apr 6, 2018 · 5 comments

Comments

@JustinChu
Copy link

JustinChu commented Apr 6, 2018

It seems there is a limit to use a uint32_t for the count parameter of the PackedArray_create() function. Do you foresee any major issues modifying the code downstream to allow for a uint64_t count so I can populate it with more than 2^32 elements?

@gpakosz
Copy link
Owner

gpakosz commented Apr 6, 2018

Hello @JustinChu

I never needed more than UINT32_MAX elements. That's why I chose uint32_t instead of size_t.
I also recall back then, Microsoft compiler didn't support %zu printf() format specifier and I would have had to use something like

#if defined(_MSCVER)
  #define SIZET_FMT "%Iu"
#elif defined(__GNUC__)
  #define SIZET_FMT "%zu"
#else
  #define SIZET_FMT "%u"
#endif

You should be just fine replacing uint32_t count with uint64_t count or size_t count. If you decide yo use size_t you need #include <stddef.h> in PackedArray.h. In any case you will need to fix -Wformat warnings on printf() calls when compiling the self test and the self bench programs with GCC or Clang.

That being said, at this point I'm undecided on whether it's a change I want to merge.

@JustinChu
Copy link
Author

JustinChu commented Apr 6, 2018

My code only needs to work in a Linux environment using gcc and maybe clang. I'll give a shot and let you know if I have any problems.

Thanks.

@JustinChu
Copy link
Author

JustinChu commented Apr 6, 2018

So far it seems to be okay. I basically changed a bunch of uint32_t to uint64_t JustinChu@bdc9163.
I tested in a few informal cases with no problems so far. I have yet to touch the simd code, however.

Unrelated question (maybe I should add this to another issue). How thread safe is the code? I assume I won't be able to atomically insert values but are at least lookups safe?

Ideally, I would like to be able to do atomic inserts with compare_and_swap (e.g. with atomic built-ins like __sync_bool_compare_and_swap) operations but that doesn't seem like something easily done with a packed array. I wonder if it is possible to use an unaligned pointer in a compare and swap operation...

@NickStrupat
Copy link

did you ever get to modifying the SIMD code?

@guinn8
Copy link

guinn8 commented Jan 13, 2022

I found that replacing all uint32_t with uint64_t in PackedArray.c and PackedArray.h got me the extra space I needed. Likely overkill but ensures I don't overflow some uint32_t I forgot about. Thanks for this libary gpakosz, super cool stuff!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants