Changeset 13498


Ignore:
Timestamp:
10/02/12 14:13:50 (12 years ago)
Author:
utke
Message:

CHG implement fos_reverse for the solver and use a view to the solution vector rather than allocating a new one and copying it

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/modules/Solverx/SolverxSeq.cpp

    r13481 r13498  
    161161/*}}}*/
    162162int EDF_fos_reverse_for_solverx(int m, double *dp_U, int n, double *dp_Z, double* dp_x, double* dp_y) { /*{{{*/
     163  // copy to transpose the matrix
     164  double* transposed=xNew<double>(m*m);
     165  for (int i=0; i<m; ++i) for (int j=0; j<m; ++j) transposed[j*m+i]=dp_x[i*m+j];
     166  gsl_matrix_view aTransposed = gsl_matrix_view_array (transposed,m,m);
     167  // the adjoint of the solution is our right-hand side
     168  gsl_vector_view x_bar=gsl_vector_view_array(dp_U,m);
     169  // the last m elements of dp_Z representing the adjoint of the right-hand side we want to compute:
     170  gsl_vector_view b_bar=gsl_vector_view_array(dp_Z+m*m,m);
     171  gsl_permutation *p = gsl_permutation_alloc (m);
     172  int permSign;
     173  gsl_linalg_LU_decomp (&aTransposed.matrix, p, &permSign);
     174  gsl_linalg_LU_solve (&aTransposed.matrix, p, &x_bar.vector, &b_bar.vector);
     175  // now do the adjoint of the matrix
     176  for (int i=0; i<m; ++i) for (int j=0; j<m; ++j) dp_Z[i*m+j]-=dp_Z[m*m+i]*dp_y[j];
     177  gsl_permutation_free(p);
     178  xDelete(transposed);
    163179  return 0;
    164180}
     
    189205        int              s;
    190206        gsl_matrix_view  a;
    191         gsl_vector_view  b;
    192         gsl_vector      *x = NULL;
     207        gsl_vector_view  b,x;
    193208        gsl_permutation *p = NULL;
    194209//      for (int i=0; i<n*n; ++i) std::cout << "SolverxSeq A["<< i << "]=" << A[i] << std::endl;
     
    201216        a = gsl_matrix_view_array (Acopy,n,n);
    202217        b = gsl_vector_view_array (B,n);
    203         x = gsl_vector_alloc (n);
     218        x = gsl_vector_view_array (X,n);
    204219
    205220        /*Run LU and solve: */
    206221        p = gsl_permutation_alloc (n);
    207222        gsl_linalg_LU_decomp (&a.matrix, p, &s);
    208         gsl_linalg_LU_solve (&a.matrix, p, &b.vector, x);
    209 
    210         //printf ("x = \n");
    211         //gsl_vector_fprintf (stdout, x, "%g");
    212 
    213         /*Copy result*/
    214         xMemCpy(X,gsl_vector_ptr(x,0),n);
    215 //      for (int i=0; i<n; ++i) std::cout << "SolverxSeq x["<< i << "]=" << X[i] << std::endl;
     223        gsl_linalg_LU_solve (&a.matrix, p, &b.vector, &x.vector);
    216224
    217225        /*Clean up and assign output pointer*/
    218226        xDelete(Acopy);
    219227        gsl_permutation_free(p);
    220         gsl_vector_free(x);
    221 #endif
    222 }
    223 /*}}}*/
     228#endif
     229}
     230/*}}}*/
Note: See TracChangeset for help on using the changeset viewer.