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

  • Home
  • SEARCH
  • 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 3676336
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:05:14+00:00 2026-05-19T03:05:14+00:00

following this previous question Malloc Memory Corruption in C , now i have another

  • 0

following this previous question Malloc Memory Corruption in C, now i have another problem.
I have the same code. Now I am trying to multiply the values contained in the arrays A * vc
and store in res. Then A is set to zero and i do a second multiplication with res and vc and i store the values in A. (A and Q are square matrices and mc and vc are N lines two columns matrices or arrays).
Here is my code :

    int jacobi_gpu(double A[], double Q[], 
           double tol, long int dim){
  int nrot, p, q, k, tid;
  double c, s;
  double *mc, *vc, *res;
  int i,kc;
  double vc1, vc2;

  mc   = (double *)malloc(2 * dim * sizeof(double));
  vc   = (double *)malloc(2 * dim * sizeof(double));
  vc   = (double *)malloc(dim * dim * sizeof(double));

  if( mc == NULL || vc == NULL){
    fprintf(stderr, "pb allocation matricre\n");
    exit(1);
  }

  nrot = 0;

  for(k = 0; k < dim - 1; k++){

    eye(mc, dim);
    eye(vc, dim);

    for(tid = 0; tid < floor(dim /2); tid++){
      p = (tid + k)%(dim - 1);
      if(tid != 0)
    q = (dim - tid + k - 1)%(dim - 1);
      else
    q = dim - 1;

      printf("p = %d | q = %d\n", p, q);
      if(fabs(A[p + q*dim]) > tol){

    nrot++;
    symschur2(A, dim, p, q, &c, &s);


    mc[2*tid] = p;                                               vc[2 * tid] = c;
    mc[2*tid + 1] = q;                                           vc[2*tid + 1] = -s;
    mc[2*tid + 2*(dim - 2*tid) - 2] = p;                         vc[2*tid + 2*(dim - 2*tid)   - 2 ] = s;
    mc[2*tid + 2*(dim - 2*tid) - 1] = q;                         vc[2 * tid + 2*(dim - 2*tid) - 1 ] = c;



    }
    }

    for( i = 0; i< dim; i++){
      for(kc=0; kc < dim; kc++){
    if( kc < floor(dim/2)) {
      vc1 = vc[2*kc + i*dim];
      vc2 = vc[2*kc + 2*(dim - 2*kc) - 2];
    }else {
      vc1 = vc[2*kc+1 + i*dim];
      vc2 = vc[2*kc - 2*(dim - 2*kc) - 1];
    }
    res[kc + i*dim] = A[mc[2*kc] + i*dim]*vc1 + A[mc[2*kc + 1] + i*dim]*vc2;
      }
    }

    zero(A, dim);

    for( i = 0; i< dim; i++){
      for(kc=0; kc < dim; k++){
    if( k < floor(dim/2)){
      vc1 = vc[2*kc + i*dim];
      vc2 = vc[2*kc + 2*(dim - 2*kc) - 2];
    }else {
      vc1 = vc[2*kc+1 + i*dim];
      vc2 = vc[2*kc - 2*(dim - 2*kc) - 1];
    }
    A[kc + i*dim] = res[mc[2*kc] + i*dim]*vc1 + res[mc[2*kc + 1] + i*dim]*vc2;
      }
    }


    affiche(mc,dim,2,"Matrice creuse");
    affiche(vc,dim,2,"Valeur creuse");

  }

  free(mc);
  free(vc);
  free(res);
  return nrot;
}

When i try to compile, i have this error :

    jacobi_gpu.c: In function ‘jacobi_gpu’:
jacobi_gpu.c:103: error: array subscript is not an integer
jacobi_gpu.c:103: error: array subscript is not an integer
jacobi_gpu.c:118: error: array subscript is not an integer
jacobi_gpu.c:118: error: array subscript is not an integer
make: *** [jacobi_gpu.o] Erreur 1

The corresponding lines are where I store the results in res and A :

res[kc + i*dim] = A[mc[2*kc] + i*dim]*vc1 + A[mc[2*kc + 1] + i*dim]*vc2;

and

A[kc + i*dim] = res[mc[2*kc] + i*dim]*vc1 + res[mc[2*kc + 1] + i*dim]*vc2;

Can someone explain me what is this error and how can i correct it?
Thanks for your help. 😉

  • 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-19T03:05:15+00:00Added an answer on May 19, 2026 at 3:05 am

    mc is of type double. It has to be integral type

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

Sidebar

Related Questions

I have ASP.Net code similar to the following (this is inside a FIELDSET): <ol>
From a previous question , I have the following: So I have implemented a
Following on from a previous question, ( previous question here ), the problem I'm
This is a follow up question to my previous question . I am trying
Following this question: Good crash reporting library in c# Is there any library like
Have you managed to get Aptana Studio debugging to work? I tried following this,
Following on from a previous question relating to heap usage restrictions , I'm looking
Much like this previous question , I wish to store a MySQL column in
In the context of this previous question I am wondering if it's possible to
Following my previous question, DAO and Service layers (JPA/Hibernate + Spring) , I decided

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.