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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:50:39+00:00 2026-05-13T16:50:39+00:00

I would like to map a thread_id. This in C/CUDA but it is more

  • 0

I would like to map a thread_id. This in C/CUDA but it is more an algebraic problem that I am trying to solve.

So the mapping I am trying to achieve is along the lines:

  • Threads 0-15: read value array[0]
  • Threads 16-31: read value [3]
  • Threads 32-47: read value [0]
  • Threads 48-63: read value [3]
  • Threads 64-79: read value array[6]
  • Threads 80-95: read value array[9]
  • Threads 96-111: read value array[6]
  • Threads 112-127: read value array[9]

and so on..

Note this is a simplification of the mapping, in reality there are more than 128 threads but the sequence is as shown and threads would always map to a multiple of three.

What formula can I use that each thread can run to find out what array position it should look at?

I would like to use some kind of formula as I have in the following example and not an explicit map or any if-statements.

To illustrate how I have solved this for a different case which required a different mapping, i.e.:

  • Threads 0-31: read value array[0]
  • Threads 32-63: read value [3]

I used the code

rintf(float(tid)/96.0)*3
  • 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-05-13T16:50:40+00:00Added an answer on May 13, 2026 at 4:50 pm

    This will work in C:

    3 * ((n>>4 & 1) + (n>>5 & ~1))
    

    where n is the thread number.

    I made the assumption here that the pattern continues beyond 128 as: 0,3,0,3,6,9,6,9,12,15,12,15,etc.

    Edit:

    This form, without bitwise operations, may be easier to understand:

    6 * (n/64) + 3 * ((n/16) % 2)
    

    It will give the same results. n is assumed to be an integer, so that division will round down.

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

Sidebar

Related Questions

Ok, NHibernate question here. I have two objects that I would like to map
I have a 320x480 PNG that I would like to texture map/manipulate on the
I would like to include a Google map in a Flash site I am
I would like to filter an array of items by using the map() function.
I would like to open a small video file and map every frames in
We have a library of ZIP files that we would like to make available
Would like to get a list of advantages and disadvantages of using Stored Procedures.
Would like to create a strong password in C++. Any suggestions? I assume it
I would like to test a string containing a path to a file for
I would like to sort an array in ascending order using C/C++ . The

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.