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

The Archive Base Latest Questions

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

Say I have a 1D array converted from a MxN 2D matrix, and I

  • 0

Say I have a 1D array converted from a MxN 2D matrix, and I want to parallelize each column and do some operations. How do I assign a thread to each column?

For example, if I have a 3×3 matrix:

1  2  3

4  5  6

7  8  9

And I want to add each number in the column depending on the column # (so 1st column will add 1, 2nd will add 2….), it then becomes:

1+1   2+1   3+1

4+2   5+2   6+2

7+3   8+3   9+3

How do I do this in CUDA? I know how to assign threads to all the elements in the array but I don’t know how to assign thread to each column. So, what I want is to send each column (1 , 2 ,3 ) ( 4 , 5 ,6 ) (7 , 8 ,9) and do the operation.

  • 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-02T18:07:10+00:00Added an answer on June 2, 2026 at 6:07 pm

    In your example you are adding numbers based on the row. Still, you know the row/column length of the matrix (you know it’s MxN). What you could do is something like:

    __global__ void MyAddingKernel(int* matrix, int M, int N)
    {
    
        int gid = threadIdx.x + blockDim.x*blockIdx.x;
        //Let's add the row number to each element
        matrix[ gid ] += gid % M;
        //Let's add the column number to each element
        matrix[ gid ] += gid % N;
    
    }
    

    If you wanted to add a different number, you could do something like:

    matrix[ gid ] += my_col_number_function(gid%N);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have an array of arrays, and I want to return the first
Say I have an array of table DDL queries and I want to get
Say I have an array of arbitrary size holding single characters. I want to
Let's say I have a javascript array with a bunch of elements (anywhere from
Let's say I have an unsorted array from 1 to 10, as shown below...
Lets say that I have an array that I want to convert to a
Let's say I have a function called MyFunction(int myArray[][]) that does some array manipulations.
Let's say I have array of bytes: byte[] arr = new byte[] { 0,
Say I have an array of Employee Objects: var Employee = function(fname, age) {
Say I have an array similar to the following and I'm looping through it

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.