Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7787467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:40:54+00:00 2026-06-01T20:40:54+00:00

In my program, I’m tracking a large number of particles through a voxel grid.

  • 0

In my program, I’m tracking a large number of particles through a voxel grid. The ratio of particles to voxels is arbitrary. At a certain point, I need to know which particles lie in which voxels, and how many do. Specifically, the voxels must know exactly which particles are contained within them. Since I can’t use anything like std::vector in CUDA, I’m using the following algorithm (at the high level):

  • Allocate an array of ints the size of the number of voxels
  • Launch threads for the all the particles, determine the voxel each one lies in, and increase the appropriate counter in my ‘bucket’ array
  • Allocate an array of pointers the size of the number of particles
  • Calculate each voxel’s offset into this new array (summing the number of particles in the voxels preceding it)
  • Place the particles in the array in an ordered fashion (I use this data to accelerate an operation later on. The speed increase is well worth the increased memory usage).

This breaks down on the second step though. I haven’t been programming in CUDA for long, and just found out that simultaneous writes among threads to the same location in global memory produce undefined results. This is reflected in the fact that I mostly get 1’s in buckets, with the occasional 2. Here’s an sketch of the code I’m using for this step:

__global__ void GPU_AssignParticles(Particle* particles, Voxel* voxels, int* buckets) {
    int tid = threadIdx.x + blockIdx.x*blockDim.x;

    if(tid < num_particles) { // <-- you can assume I actually passed this to the function :)
        // Some math to determine the index of the voxel which this particle
        // resides in.
        buckets[index] += 1;
    }
}

My question is, what’s the proper way to generate these counts in CUDA?

Also, is there a way to store references to the particles within the voxels? The issue I see there is that the number of particles within a voxel constantly changes, so new arrays would have to be deallocated and reallocated almost every frame.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:40:56+00:00Added an answer on June 1, 2026 at 8:40 pm

    Although there may be more efficient solutions for calculating the bucket counts, a first working solution is to use your current approach, but using an atomic increment. This way only one thread at a time increments the bucket count atomically (synchronized over the whole grid):

    if(tid < num_particles) {
        // ...
        atomicAdd(&buckets[index], 1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My program receives an executable binary file through a TCP socket. I need to
My program needs to receive strings through the serialport. Problem is that the program
My program collects the number of bottles collected by four rooms. When the user
This program is supposed to calculate the number of degrees below 60 on a
My program need to occupy some resources. I want it to release those resources
Program has more than one entry point defined: 'Class.Main()'. Compile with /main to specify
The program I'm writing is suppose to open two directories and read through the
Program is receiving approximately 50,000 numbers every second. At ANY given moment, I need
program Project1; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; var ints: array[1..2] of Integer =
Program returns an error of, expected PWideChar instead of string procedure TForm1.Button1Click(Sender: TObject); var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.