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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:31:09+00:00 2026-06-14T09:31:09+00:00

My problem is this: I have an array in 3D and I cannot use

  • 0

My problem is this: I have an array in 3D and I cannot use the malloc3D, and I need to convert and manipulate 1D array on GPU. But I don’t know how do it. In this moment I am using

#define nx  8
#define ny  6
#define nz  4

to define the matriz array.. 4 matrices of 6 row with 8 columns with index i,j,k.

u[i][j][k]

and I declaration of:

cudaMalloc( (void**)&dev_u, ny * nx * nz * sizeof(float) ) ;
cudaMemcpy( dev_u, u, ny * nx * nz * sizeof(float), cudaMemcpyHostToDevice );
dim3 dimBlock(nx,ny,nz);
dim3 dimGrid(1,1);
FTCS3D<<<dimGrid, dimBlock>>>( dev_u );
cudaMemcpy( u, dev_u, ny * nx * nz * sizeof(float), cudaMemcpyDeviceToHost );

Inside the GPU:

__global__ void FTCS3D( float *u )
{
    int i = threadIdx.y+blockDim.y*blockIdx.y;
    int j = threadIdx.x+blockDim.x*blockIdx.x;
    int k = threadIdx.z+blockDim.z*blockIdx.z;
    int offset = i * nx + j + ny * nx * z;
    int totid=nx*ny*nz;

    if (offset < totid)
    {
        if ( offset ==1 )
           u[offset]=5.0;
   }
}

The number 5 appears in other matriz not in u[0][0][1], I do not have any idea about how to index all variables inside the offset remember I HAVE TO DO IT in this way of 1D vector.

  • 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-14T09:31:10+00:00Added an answer on June 14, 2026 at 9:31 am

    If you have a array3D [HEIGHT][WIDTH] [DEPTH] then you could turn it into array1D [HEIGHT * WIDTH * DEPTH].

    Out side your kernel you convert the 3D to 1D array

    for (int x = 0, k=0; x < HEIGHT; x++)
      for (int y = 0; y < WIDTH; y++)
         for (int z = 0; z < DEPTH; z++)
            a1D[k++] = a3D[x][y][z]
    

    Why not only one dimension in you cuda?

    __global__ void FTCS3D( float *u,int HEIGHT, int WIDTH, int DEPTH)
    {   
        int x = threadIdx.x+blockDim.x*blockIdx.x;
        int totid = HEIGHT * WIDTH * DEPTH;
    
        if (x < totid)
        {
           if (x==1 )
              u[x]=5.0;
         }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a trouble with this little problem. Let's say, I have an array,
This problem is taken from interviewstreet.com Given array of integers Y=y1,...,yn, we have n
I have some problem to order an array by a field of this, here
I don't know a better title, but I'll describe the problem. A piece of
Hello folkes I have this little problem for which I cannot find a suitable
I have this pattern written ^.*\.(?!jpg$|png$).+$ However there is a problem - this pattern
I'm developing an Android application with a spinner. I have this problem: This is
I have this problem: I want to generate a new source code file from
I have this problem: $id is id for each user $img = 'http://www.somesite.com/pictures/'; $no_img
I have this problem since I'm beginning in OOP programming I want to close

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.