00001 /* 00002 * N_Vector_NrnThread derived from N_Vector_Serial SunDials version 00003 * by replacing every occurrence of nrnthread with nrnthread in the various 00004 * cases and then modifying the relevant prototypes. 00005 * We only re-implement the ones that are used by cvodes and ida 00006 */ 00007 00008 /* 00009 * ----------------------------------------------------------------- 00010 * $Revision: 855 $ 00011 * $Date: 2005-02-09 18:15:46 -0500 (Wed, 09 Feb 2005) $ 00012 * ----------------------------------------------------------------- 00013 * Programmer(s): Scott D. Cohen, Alan C. Hindmarsh, Radu Serban, 00014 * and Aaron Collier @ LLNL 00015 * ----------------------------------------------------------------- 00016 * Copyright (c) 2002, The Regents of the University of California. 00017 * Produced at the Lawrence Livermore National Laboratory. 00018 * All rights reserved. 00019 * For details, see sundials/shared/LICENSE. 00020 * ----------------------------------------------------------------- 00021 * This is the header file for the nrnthread implementation of the 00022 * NVECTOR module. 00023 * 00024 * Part I contains declarations specific to the nrnthread 00025 * implementation of the supplied NVECTOR module. 00026 * 00027 * Part II defines accessor macros that allow the user to 00028 * efficiently use the type N_Vector without making explicit 00029 * references to the underlying data structure. 00030 * 00031 * Part III contains the prototype for the constructor N_VNew_NrnThread 00032 * as well as implementation-specific prototypes for various useful 00033 * vector operations. 00034 * 00035 * Notes: 00036 * 00037 * - The definition of the generic N_Vector structure can be found 00038 * in the header file shared/include/nvector.h. 00039 * 00040 * - The definition of the type realtype can be found in the 00041 * header file shared/include/sundialstypes.h, and it may be 00042 * changed (at the configuration stage) according to the user's 00043 * needs. The sundialstypes.h file also contains the definition 00044 * for the type booleantype. 00045 * 00046 * - N_Vector arguments to arithmetic vector operations need not 00047 * be distinct. For example, the following call: 00048 * 00049 * N_VLinearSum_NrnThread(a,x,b,y,y); 00050 * 00051 * (which stores the result of the operation a*x+b*y in y) 00052 * is legal. 00053 * ----------------------------------------------------------------- 00054 */ 00055 00056 #ifndef _NVECTOR_NRNTHREAD_H 00057 #define _NVECTOR_NRNTHREAD_H 00058 00059 #ifdef __cplusplus /* wrapper to enable C++ usage */ 00060 extern "C" { 00061 #endif 00062 00063 #include "nvector.h" 00064 #include "sundialstypes.h" 00065 00066 /* 00067 * ----------------------------------------------------------------- 00068 * PART I: NRNTHREAD implementation of N_Vector 00069 * ----------------------------------------------------------------- 00070 */ 00071 00072 /* nrnthread implementation of the N_Vector 'content' structure 00073 contains the length of the vector, nthread, and a pointer to 00074 nthread N_Vector (serial) 00075 */ 00076 00077 struct _N_VectorContent_NrnThread { 00078 long int length; 00079 int nt; /* number of threads */ 00080 booleantype own_data; 00081 N_Vector *data; /* nt of them (N_Vector_Serial) */ 00082 }; 00083 00084 typedef struct _N_VectorContent_NrnThread *N_VectorContent_NrnThread; 00085 00086 /* Note: documentation below may not be completely transformed from the 00087 N_Vector_Serial case 00088 */ 00089 00090 /* 00091 * ----------------------------------------------------------------- 00092 * PART II: macros NV_CONTENT_S, NV_DATA_S, NV_OWN_DATA_S, 00093 * NV_LENGTH_S, and NV_Ith_S 00094 * ----------------------------------------------------------------- 00095 * In the descriptions below, the following user declarations 00096 * are assumed: 00097 * 00098 * N_Vector v; 00099 * long int i; 00100 * 00101 * (1) NV_CONTENT_NT 00102 * 00103 * This routines gives access to the contents of the nrnthread 00104 * vector N_Vector. 00105 * 00106 * The assignment v_cont = NV_CONTENT_NT(v) sets v_cont to be 00107 * a pointer to the nrnthread N_Vector content structure. 00108 * 00109 * (2) NV_SUBVEC_NT and NV_LENGTH_NT 00110 * 00111 * These routines give access to the individual parts of 00112 * the content structure of a nrnthread N_Vector. 00113 * 00114 * The assignment v_data = NV_SUBVEC_NT(v, i) sets v_data to be 00115 * a pointer to the ith N_Vector of v. The assignment 00116 * NV_SUBVEC_NT(v, i) = data_V sets the ith component N_Vector of v to 00117 * be data_v by storing the pointer data_v. 00118 * 00119 * The assignment v_llen = NV_SIZE_NT(v,i) sets v_llen to be 00120 * the length of the ith component of v. The call NV_LENGTH_NT(v) = len_v sets 00121 * the length of v to be len_v. 00122 * 00123 * (3) NV_Ith_NT 00124 * 00125 * In the following description, the components of an 00126 * N_Vector are numbered 0..n-1, where n is the length of v. 00127 * 00128 * The assignment r = NV_Ith_S(v,i) sets r to be the value of 00129 * the ith component of v. The assignment NV_Ith_S(v,i) = r 00130 * sets the value of the ith component of v to be r. 00131 * 00132 * Note: When looping over the components of an N_Vector v, it is 00133 * more efficient to first obtain the component array via 00134 * v_data = NV_DATA_S(v) and then access v_data[i] within the 00135 * loop than it is to use NV_Ith_S(v,i) within the loop. 00136 * ----------------------------------------------------------------- 00137 */ 00138 00139 #define NV_CONTENT_NT(v) ( (N_VectorContent_NrnThread)(v->content) ) 00140 00141 #define NV_LENGTH_NT(v) ( NV_CONTENT_NT(v)->length ) 00142 00143 #define NV_NT_NT(v) ( NV_CONTENT_NT(v)->nt ) 00144 00145 #define NV_OWN_DATA_NT(v) ( NV_CONTENT_NT(v)->own_data ) 00146 00147 #define NV_DATA_NT(v) ( NV_CONTENT_NT(v)->data ) 00148 00149 #define NV_SUBVEC_NT(v, i) ( NV_CONTENT_NT(v)->data[i] ) 00150 00151 #define NV_Ith_NT(v,i) ( NV_DATA_NT(v)[i] ) /* wrong but not needed */ 00152 00153 /* 00154 * ----------------------------------------------------------------- 00155 * PART III: functions exported by nvector_nrnthread 00156 * 00157 * CONSTRUCTORS: 00158 * N_VNew_NrnThread 00159 * N_VNewEmpty_NrnThread 00160 * N_VClone_NrnThread 00161 * N_VCloneEmpty_NrnThread 00162 * N_VMake_NrnThread 00163 * N_VNewVectorArray_NrnThread 00164 * N_VNewVectorArrayEmpty_NrnThread 00165 * DESTRUCTORS: 00166 * N_VDestroy_NrnThread 00167 * N_VDestroyVectorArray_NrnThread 00168 * ----------------------------------------------------------------- 00169 */ 00170 00171 /* 00172 * ----------------------------------------------------------------- 00173 * Function : N_VNew_NrnThread 00174 * ----------------------------------------------------------------- 00175 * This function creates and allocates memory for a nrnthread vector. 00176 * ----------------------------------------------------------------- 00177 */ 00178 00179 N_Vector N_VNew_NrnThread(long int vec_length, int nthread, long int* sizes ); 00180 00181 /* 00182 * ----------------------------------------------------------------- 00183 * Function : N_VNewEmpty_NrnThread 00184 * ----------------------------------------------------------------- 00185 * This function creates a new nrnthread N_Vector with an empty (NULL) 00186 * data array. 00187 * ----------------------------------------------------------------- 00188 */ 00189 00190 N_Vector N_VNewEmpty_NrnThread(long int vec_length, int nthread, long int* sizes); 00191 00192 /* 00193 * ----------------------------------------------------------------- 00194 * Function : N_VCloneEmpty_NrnThread 00195 * ----------------------------------------------------------------- 00196 * This function creates a new nrnthread N_Vector with an empty (NULL) 00197 * data array. 00198 * ----------------------------------------------------------------- 00199 */ 00200 00201 N_Vector N_VCloneEmpty_NrnThread(N_Vector w); 00202 00203 /* 00204 * ----------------------------------------------------------------- 00205 * Function : N_VMake_NrnThread 00206 * ----------------------------------------------------------------- 00207 * This function creates and allocates memory for a nrnthread vector 00208 * with a user-supplied data array. 00209 * ----------------------------------------------------------------- 00210 */ 00211 00212 /*not implemented*/ 00213 N_Vector N_VMake_NrnThread(long int vec_length, realtype *v_data); 00214 00215 /* 00216 * ----------------------------------------------------------------- 00217 * Function : N_VNewVectorArray_NrnThread 00218 * ----------------------------------------------------------------- 00219 * This function creates an array of 'count' nrnthread vectors. This 00220 * array of N_Vectors can be freed using N_VDestroyVectorArray 00221 * (defined by the generic NVECTOR module). 00222 * ----------------------------------------------------------------- 00223 */ 00224 00225 N_Vector *N_VNewVectorArray_NrnThread(int count, long int vec_length, 00226 int nthread, long int* sizes); 00227 00228 /* 00229 * ----------------------------------------------------------------- 00230 * Function : N_VNewVectorArrayEmpty_NrnThread 00231 * ----------------------------------------------------------------- 00232 * This function creates an array of 'count' nrnthread vectors each 00233 * with an empty (NULL) data array. 00234 * ----------------------------------------------------------------- 00235 */ 00236 00237 N_Vector *N_VNewVectorArrayEmpty_NrnThread(int count, long int vec_length, 00238 int nthread, long int* sizes); 00239 00240 /* 00241 * ----------------------------------------------------------------- 00242 * Function : N_VDestroyVectorArray_NrnThread 00243 * ----------------------------------------------------------------- 00244 * This function frees an array of N_Vector created with 00245 * N_VNewVectorArray_NrnThread. 00246 * ----------------------------------------------------------------- 00247 */ 00248 00249 void N_VDestroyVectorArray_NrnThread(N_Vector *vs, int count); 00250 00251 /* 00252 * ----------------------------------------------------------------- 00253 * Function : N_VPrint_NrnThread 00254 * ----------------------------------------------------------------- 00255 * This function prints the content of a nrnthread vector to stdout. 00256 * ----------------------------------------------------------------- 00257 */ 00258 00259 void N_VPrint_NrnThread(N_Vector v); 00260 00261 /* 00262 * ----------------------------------------------------------------- 00263 * nrnthread implementations of various useful vector operations 00264 * ----------------------------------------------------------------- 00265 */ 00266 00267 N_Vector N_VClone_NrnThread(N_Vector w); 00268 void N_VDestroy_NrnThread(N_Vector v); 00269 void N_VSpace_NrnThread(N_Vector v, long int *lrw, long int *liw); 00270 realtype *N_VGetArrayPointer_NrnThread(N_Vector v); 00271 void N_VSetArrayPointer_NrnThread(realtype *v_data, N_Vector v); 00272 void N_VLinearSum_NrnThread(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z); 00273 void N_VConst_NrnThread(realtype c, N_Vector z); 00274 void N_VProd_NrnThread(N_Vector x, N_Vector y, N_Vector z); 00275 void N_VDiv_NrnThread(N_Vector x, N_Vector y, N_Vector z); 00276 void N_VScale_NrnThread(realtype c, N_Vector x, N_Vector z); 00277 void N_VAbs_NrnThread(N_Vector x, N_Vector z); 00278 void N_VInv_NrnThread(N_Vector x, N_Vector z); 00279 void N_VAddConst_NrnThread(N_Vector x, realtype b, N_Vector z); 00280 realtype N_VDotProd_NrnThread(N_Vector x, N_Vector y); 00281 realtype N_VMaxNorm_NrnThread(N_Vector x); 00282 realtype N_VWrmsNorm_NrnThread(N_Vector x, N_Vector w); 00283 realtype N_VWrmsNormMask_NrnThread(N_Vector x, N_Vector w, N_Vector id); 00284 realtype N_VMin_NrnThread(N_Vector x); 00285 realtype N_VWL2Norm_NrnThread(N_Vector x, N_Vector w); 00286 realtype N_VL1Norm_NrnThread(N_Vector x); 00287 void N_VCompare_NrnThread(realtype c, N_Vector x, N_Vector z); 00288 booleantype N_VInvTest_NrnThread(N_Vector x, N_Vector z); 00289 booleantype N_VConstrMask_NrnThread(N_Vector c, N_Vector x, N_Vector m); 00290 realtype N_VMinQuotient_NrnThread(N_Vector num, N_Vector denom); 00291 00292 #ifdef __cplusplus 00293 } 00294 #endif 00295 00296 #endif