Nek5000
SEM for Incompressible NS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 "c99.h"
6 #include "name.h"
7 #include "fail.h"
8 #include "types.h"
9 #include "mem.h"
10 #include "comm.h"
11 #include "crs.h"
12 
13 /*--------------------------------------------------------------------------
14  FORTRAN Interface to coarse solver
15  --------------------------------------------------------------------------*/
16 
17 #undef crs_setup
18 #undef crs_solve
19 #undef crs_stats
20 #undef crs_free
21 #define ccrs_setup PREFIXED_NAME(crs_setup)
22 #define ccrs_solve PREFIXED_NAME(crs_solve)
23 #define ccrs_stats PREFIXED_NAME(crs_stats)
24 #define ccrs_free PREFIXED_NAME(crs_free )
25 
26 #define fcrs_setup FORTRAN_NAME(crs_setup,CRS_SETUP)
27 #define fcrs_solve FORTRAN_NAME(crs_solve,CRS_SOLVE)
28 #define fcrs_stats FORTRAN_NAME(crs_stats,CRS_STATS)
29 #define fcrs_free FORTRAN_NAME(crs_free ,CRS_FREE)
30 
31 static struct crs_data **handle_array = 0;
32 static int handle_max = 0;
33 static int handle_n = 0;
34 
35 void fcrs_setup(sint *handle, const MPI_Fint *comm, const sint *np,
36  const sint *n, const slong id[], const sint *nz,
37  const sint Ai[], const sint Aj[], const double A[],
38  const sint *null_space)
39 {
40  struct comm c;
41  if(handle_n==handle_max)
43  handle_array=trealloc(struct crs_data*,handle_array,handle_max);
44  comm_init_check(&c, *comm, *np);
45  handle_array[handle_n]=ccrs_setup(*n,(const ulong*)id,
46  *nz,(const uint*)Ai,(const uint*)Aj,A,
47  *null_space,&c);
48  comm_free(&c);
49  *handle = handle_n++;
50 }
51 
52 #define CHECK_HANDLE(func) do \
53  if(*handle<0 || *handle>=handle_n || !handle_array[*handle]) \
54  fail(1,__FILE__,__LINE__,func ": invalid handle"); \
55 while(0)
56 
57 void fcrs_solve(const sint *handle, double x[], double b[])
58 {
59  CHECK_HANDLE("crs_solve");
60  ccrs_solve(x,handle_array[*handle],b);
61 }
62 
63 void fcrs_stats(const sint *handle)
64 {
65  CHECK_HANDLE("crs_stats");
66  ccrs_stats(handle_array[*handle]);
67 }
68 
70 {
71  CHECK_HANDLE("crs_free");
72  ccrs_free(handle_array[*handle]);
73  handle_array[*handle] = 0;
74 }
75 
76 
#define slong
Definition: types.h:74
#define ccrs_stats
Definition: fcrs.c:23
#define uint
Definition: types.h:70
#define sint
Definition: types.h:69
static int handle_n
Definition: fcrs.c:33
n
Definition: xxt_test.m:73
#define fcrs_solve
Definition: fcrs.c:27
#define x
#define trealloc(type, ptr, count)
Definition: mem.h:95
#define fcrs_free
Definition: fcrs.c:29
ulong A[NUM][SI]
Definition: sort_test.c:17
#define CHECK_HANDLE(func)
Definition: fcrs.c:52
Definition: comm.h:85
static void comm_free(struct comm *c)
Definition: comm.h:176
static struct crs_data ** handle_array
Definition: fcrs.c:31
#define fcrs_stats
Definition: fcrs.c:28
const uint Ai[3][32]
Definition: xxt_test.c:80
#define comm_init_check(c, ce, np)
Definition: comm.h:161
#define ulong
Definition: types.h:75
#define ccrs_setup
Definition: fcrs.c:21
#define fcrs_setup
Definition: fcrs.c:26
const uint Aj[3][32]
Definition: xxt_test.c:85
int MPI_Fint
Definition: comm.h:71
static int handle_max
Definition: fcrs.c:32
establishes some macros to establish naming conventions
static uint np
Definition: findpts_test.c:63
#define ccrs_free
Definition: fcrs.c:24
#define ccrs_solve
Definition: fcrs.c:22
const uint nz[3]
Definition: xxt_test.c:78