accelerInt  v0.1
solver_cvodes.c
Go to the documentation of this file.
1 
10 #include "header.h"
11 #include "solver.h"
12 
13 /* CVODES INCLUDES */
14 #include "sundials/sundials_types.h"
15 #include "sundials/sundials_math.h"
16 #include "sundials/sundials_nvector.h"
17 #include "nvector/nvector_serial.h"
18 #include "cvodes/cvodes.h"
19 #include "cvodes/cvodes_lapack.h"
20 
21 extern N_Vector *y_locals;
22 extern double* y_local_vectors;
23 extern void** integrators;
24 
25 #ifdef GENERATE_DOCS
26 namespace cvode {
27 #endif
28 
39 void intDriver (const int NUM, const double t, const double t_end,
40  const double *pr_global, double *y_global)
41 {
42  int tid;
43  double t_next;
44  #pragma omp parallel for shared(y_global, pr_global, integrators, y_locals) private(tid, t_next)
45  for (tid = 0; tid < NUM; ++tid) {
46  int index = omp_get_thread_num();
47 
48  // local array with initial values
49  N_Vector fill = y_locals[index];
50  double pr_local = pr_global[tid];
51 
52  // load local array with initial values from global array
53  double* y_local = NV_DATA_S(fill);
54 
55  for (int i = 0; i < NSP; i++)
56  {
57  y_local[i] = y_global[tid + i * NUM];
58  }
59 
60  //reinit this integrator for time t, w/ updated state
61  int flag = CVodeReInit(integrators[index], t, fill);
62  if (flag != CV_SUCCESS)
63  {
64  printf("Error reinitializing integrator for thread %d, code: %d\n", tid, flag);
65  exit(flag);
66  }
67 
68  //set user data to Pr
69  flag = CVodeSetUserData(integrators[index], &pr_local);
70  if (flag != CV_SUCCESS)
71  {
72  printf("Error setting user data for thread %d, code: %d\n", tid, flag);
73  exit(flag);
74  }
75 
76  //set end time
77  flag = CVodeSetStopTime(integrators[index], t_end);
78  if (flag != CV_SUCCESS)
79  {
80  printf("Error setting end time for thread %d, code: %d\n", tid, flag);
81  exit(flag);
82  }
83 
84  // call integrator for one time step
85  flag = CVode(integrators[index], t_end, fill, &t_next, CV_NORMAL);
86  if ((flag != CV_SUCCESS && flag != CV_TSTOP_RETURN) || t_next != t_end)
87  {
88  printf("Error on integration step for thread %d, code %d\n", tid, flag);
89  exit(flag);
90  }
91 
92  // update global array with integrated values
93  for (int i = 0; i < NSP; i++)
94  {
95  y_global[tid + i * NUM] = y_local[i];
96  }
97 
98  } // end tid loop
99 
100 } // end intDriver
101 
102 #ifdef GENERATE_DOCS
103 }
104 #endif
An example header file that defines system size and other required methods for integration of the van...
#define NSP
The IVP system size.
Definition: header.cuh:20
void ** integrators
Definition: cvodes_init.c:34
double * y_local_vectors
Definition: cvodes_init.c:32
N_Vector * y_locals
Definition: cvodes_init.c:30
void ** integrators
Definition: cvodes_init.c:34
Contains skeleton of all methods that need to be defined on a per solver basis.
void intDriver(const int NUM, const double t, const double t_end, const double *pr_global, double *y_global)
Integration driver for the CPU integrators.
Definition: solver_cvodes.c:39
N_Vector * y_locals
Definition: cvodes_init.c:30