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 7810199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:41:02+00:00 2026-06-02T03:41:02+00:00

So, here’s the question. I want to do a computation in CUDA where I

  • 0

So, here’s the question. I want to do a computation in CUDA where I have a large 1D array (which represents a lattice), I partition it into subarrays of length #part, and I want each thread to do a couple of computations on each subarray.

More specifically, let’s say that we have a number of threads, #threads, and a number of blocks, #blocks. The array is of size N = 2 * #part * #threads * #blocks. If we number the subarrays from 1 to 2*#blocks*#threads, we want to first use the #threads*#blocks threads to do computation on the subarrays with an even number and then the same number of threads to do computation on the subarrays with an odd number.

I thought that I could have a local index in each thread which would denote from where it’s subarray would start.

So, I used the following index :

localIndex = #part * (2 * threadIdx.x + var) + 2 * #part  * #Nthreads * blockIdx.x;

var is either 1 or 0, depending on if we want to have the thread do computation on an subarray with an even or an odd number.

I’ve tried to run it and it seems that something goes wrong when I use more than one blocks. Have I done something wrong with the indexing?

Thanks.

  • 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-02T03:41:04+00:00Added an answer on June 2, 2026 at 3:41 am

    Why is it important that the threads collectively do first even, then the odd subarrays, since block and thread execution is not guaranteed to be in order there is no benefit?

    Assuming you index only using x-dimension for your kernel dimension setup:

    subArrayIndexEven = 2 * (blockIdx.x * blockDim.x + threadIdx.x) * part  
    subArrayIndexOdd = subArrayIndexEven + part
    

    Prove:

    BLOCK_SIZE = 3
    NUM_OF_BLOCKS = 2
    PART = 4

    N = 2 * 3 * 2 * 4 = 48

    T(threadIdx.x, blockIdx.x)
    T(0, 1) -> even = 2 * (1 * 3 + 0) * 4 = 24, odd = 28
    T(1, 1) -> even = 2 * (1 * 3 + 1) * 4 = 32, odd = 36
    T(2, 1) -> even = 2 * (1 * 3 + 2) * 4 = 40, odd = 44

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my situation. I have a DotNetNuke application. I want to link to an
Here is my code...I have two dimensional matrices A,B. I want to develop the
Here a simple question : What do you think of code which use try
Here's a problem I ran into recently. I have attributes strings of the form
Here is the issue I am having: I have a large query that needs
Here's the context: I have a file (or stream), and I want to process
Here's my situation: I have a Data Template set up which contains a ToggleButton
Here's the thing: I want to add some images programmatically. The images should have
Here is a complete example. I want to forbid using A::set from objects casted
Here's what I want to do: Given a table PeopleOutfit (id int primary key,

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.