Array subscript is not an integer

Posted by Dimitri on Stack Overflow See other posts from Stack Overflow or by Dimitri
Published on 2011-01-08T17:26:38Z Indexed on 2011/01/08 17:54 UTC
Read the original article Hit count: 255

Filed under:
|
|
|

Hello folks, 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. ;)

© Stack Overflow or respective owner

Related posts about c

    Related posts about arrays