KTH framework for Nek5000 toolboxes; testing version  0.0.1
fcrs.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stddef.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include "gslib.h"
6 #include "crs.h"
7 
8 /*--------------------------------------------------------------------------
9  FORTRAN wrapper interface to coarse solver
10  --------------------------------------------------------------------------*/
11 
12 #undef crs_xxt_setup
13 #undef crs_xxt_solve
14 #undef crs_xxt_stats
15 #undef crs_xxt_free
16 #define ccrs_xxt_setup PREFIXED_NAME(crs_xxt_setup)
17 #define ccrs_xxt_solve PREFIXED_NAME(crs_xxt_solve)
18 #define ccrs_xxt_stats PREFIXED_NAME(crs_xxt_stats)
19 #define ccrs_xxt_free PREFIXED_NAME(crs_xxt_free )
20 
21 #undef crs_amg_setup
22 #undef crs_amg_solve
23 #undef crs_amg_stats
24 #undef crs_amg_free
25 #define ccrs_amg_setup PREFIXED_NAME(crs_amg_setup)
26 #define ccrs_amg_solve PREFIXED_NAME(crs_amg_solve)
27 #define ccrs_amg_stats PREFIXED_NAME(crs_amg_stats)
28 #define ccrs_amg_free PREFIXED_NAME(crs_amg_free )
29 
30 #define fcrs_setup FORTRAN_NAME(crs_setup,CRS_SETUP)
31 #define fcrs_solve FORTRAN_NAME(crs_solve,CRS_SOLVE)
32 #define fcrs_stats FORTRAN_NAME(crs_stats,CRS_STATS)
33 #define fcrs_free FORTRAN_NAME(crs_free ,CRS_FREE)
34 
35 static struct crs_data **handle_array = 0;
36 static int handle_max = 0;
37 static int handle_n = 0;
38 static int *sid_array;
39 
40 #define CHECK_HANDLE(func) do \
41  if(*handle<0 || *handle>=handle_n || !handle_array[*handle]) \
42  fail(1,__FILE__,__LINE__,func ": invalid handle"); \
43 while(0)
44 
45 void fcrs_setup(sint *handle, const sint *sid, const MPI_Fint *comm, const sint *np,
46  const sint *n, const slong id[], const sint *nz,
47  const sint Ai[], const sint Aj[], const double A[],
48  const sint *null_space, const double *param,
49  const char *datafname, uint *ierr)
50 {
51  struct comm c;
52  if(handle_n==handle_max)
53  handle_max+=handle_max/2+1,
54  handle_array=trealloc(struct crs_data*,handle_array,handle_max),
55  sid_array=trealloc(int,sid_array,handle_max);
56  comm_init_check(&c, *comm, *np);
57 
58  sid_array[handle_n]=*sid;
59 
60  switch(sid_array[handle_n]) {
61  case 0: handle_array[handle_n]=ccrs_xxt_setup(*n,(const ulong*)id,
62  *nz,(const uint*)Ai,(const uint*)Aj,A,
63  *null_space,&c); break;
64  case 1: handle_array[handle_n]=ccrs_amg_setup(*n,(const ulong*)id,
65  *nz,(const uint*)Ai,(const uint*)Aj,A,
66  *null_space,&c,
67  datafname,ierr); break;
68  case 2: handle_array[handle_n]=ccrs_hypre_setup(*n,(const ulong*)id,
69  *nz,(const uint*)Ai,(const uint*)Aj,A,
70  *null_space,&c,param); break;
71  }
72 
73  comm_free(&c);
74  *handle = handle_n++;
75 }
76 
77 void fcrs_solve(const sint *handle, double x[], double b[])
78 {
79  CHECK_HANDLE("crs_solve");
80  switch(sid_array[*handle]) {
81  case 0: ccrs_xxt_solve(x,handle_array[*handle],b); break;
82  case 1: ccrs_amg_solve(x,handle_array[*handle],b); break;
83  case 2: ccrs_hypre_solve(x,handle_array[*handle],b); break;
84  }
85 }
86 
87 void fcrs_free(sint *handle)
88 {
89  CHECK_HANDLE("crs_free");
90  switch(sid_array[*handle]) {
91  case 0: ccrs_xxt_free(handle_array[*handle]); break;
92  case 1: ccrs_amg_free(handle_array[*handle]); break;
93  case 2: ccrs_hypre_free(handle_array[*handle]); break;
94  }
95  handle_array[*handle] = 0;
96 }
struct crs_data * ccrs_hypre_setup(uint n, const ulong *id, uint nz, const uint *Ai, const uint *Aj, const double *Av, const uint nullspace, const struct comm *comm, const double *param)
Definition: crs_hypre.c:424
void ccrs_hypre_free(struct crs_data *data)
void ccrs_hypre_solve(double *x, struct crs_data *data, double *b)
#define CHECK_HANDLE(func)
Definition: fcrs.c:40
#define ccrs_xxt_free
Definition: fcrs.c:19
#define fcrs_solve
Definition: fcrs.c:31
#define ccrs_amg_setup
Definition: fcrs.c:25
#define ccrs_xxt_solve
Definition: fcrs.c:17
#define ccrs_xxt_setup
Definition: fcrs.c:16
#define ccrs_amg_solve
Definition: fcrs.c:26
#define ccrs_amg_free
Definition: fcrs.c:28
#define fcrs_free
Definition: fcrs.c:33
#define fcrs_setup
Definition: fcrs.c:30
int null_space
Definition: crs_amg.c:116
struct comm comm
Definition: crs_amg.c:112