source: trunk/LMDZ.TITAN/libf/chimtitan/solve_lapack.c @ 3529

Last change on this file since 3529 was 1968, checked in by jvatant, 6 years ago

Minor follow-on of r1965 - to be able to call Fortran routines with gcc compiler
you need trailing underscores. Also add prototype for safety.
--JVO

File size: 1.0 KB
Line 
1/* Call to LAPACK matrix inversion dgesv */
2/* ~60 times quicker than the Numerical Recipes standard solver */
3/* Author : Jan Vatant d'Ollone 2018 */
4
5#include "titan.h"
6
7/* DGESV prototype */
8extern void dgesv_(int* n, int* nrhs, double* a, int* lda, int* ipiv,
9               double* b, int* ldb, int* info);
10
11/*Main*/
12void solve_lapack( double ***aa, int m, int n0, int n1 )
13{
14   int i,j,k;
15   int n=n1-n0+1, ok;
16   int ipiv[n];
17   double a[n*n];
18   double b[n*n];
19   
20   for( i = 0; i < n; i++ ) for( j = 0; j < n; j++ ) a[j+n*i]=aa[m][i+n0][j+n0];
21
22   for( i = 0; i < n; i++ )
23   {
24      for( k = 0; k < n; k++ )
25         b[k+n*i] = 0.0e0;
26      b[i+n*i] = 1.0e0;
27   }
28
29   dgesv_(&n,&n,a,&n,ipiv,b,&n,&ok); /* Lapack subroutine */
30   
31   if( ok > 0 ) {
32       printf( "The diagonal element of the triangular factor of A,\n" );
33       printf( "U(%i,%i) is zero, so that A is singular;\n", ok, ok );
34       printf( "the solution could not be computed.\n" );
35       exit( 1 );
36   }
37   
38   for( i = 0; i < n; i++ ) for( j = 0; j < n; j++ ) aa[m][i+n0][j+n0]=b[j+n*i];
39
40}
Note: See TracBrowser for help on using the repository browser.