Changeset 12446
- Timestamp:
- 06/18/12 13:09:02 (13 years ago)
- Location:
- issm/trunk-jpl/src/c
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/matlab/io/MatlabMatrixToDoubleMatrix.cpp
r12434 r12446 39 39 40 40 if(rows*cols){ 41 matrix=xNew Init<double>(rows*cols,0.0);41 matrix=xNewZeroInit<double>(rows*cols); 42 42 43 43 /*Now, get ir,jc and pr: */ … … 64 64 /*Create serial matrix: */ 65 65 if(rows*cols){ 66 matrix=xNew Init<double>(rows*cols,0.0);66 matrix=xNewZeroInit<double>(rows*cols); 67 67 68 68 for(i=0;i<rows;i++){ … … 81 81 /*Create serial matrix: */ 82 82 if(rows*cols){ 83 matrix=xNew Init<double>(rows*cols,0.0);83 matrix=xNewZeroInit<double>(rows*cols); 84 84 85 85 for(i=0;i<rows;i++){ … … 98 98 /*Create serial matrix: */ 99 99 if(rows*cols){ 100 matrix=xNew Init<double>(rows*cols,0.0);100 matrix=xNewZeroInit<double>(rows*cols); 101 101 102 102 for(i=0;i<rows;i++){ -
issm/trunk-jpl/src/c/matlab/io/MatlabNArrayToNArray.cpp
r12434 r12446 51 51 nz=(int)((double)nnz/(double)rows); 52 52 53 matrix=xNew Init<double>(rows*cols,0.0);53 matrix=xNewZeroInit<double>(rows*cols); 54 54 55 55 /*Now, get ir,jc and pr: */ … … 74 74 75 75 /*Create serial matrix: */ 76 matrix=xNew Init<double>(numel,0.0);76 matrix=xNewZeroInit<double>(numel); 77 77 78 78 dims=xNew<int>(ndims); … … 131 131 nz=(int)((double)nnz/(double)rows); 132 132 133 matrix=xNew Init<bool>(rows*cols,false);133 matrix=xNewZeroInit<bool>(rows*cols); 134 134 135 135 /*Now, get ir,jc and pm: */ -
issm/trunk-jpl/src/c/matlab/io/MatlabVectorToDoubleVector.cpp
r12434 r12446 51 51 52 52 if(rows){ 53 vector=xNew Init<double>(rows,0.0);53 vector=xNewZeroInit<double>(rows); 54 54 55 55 /*Now, get ir,jc and pr: */ -
issm/trunk-jpl/src/c/modules/KMLMeshWritex/KMLMeshWritex.cpp
r12442 r12446 120 120 _printf_(true,"Creating the node connectivity table.\n"); 121 121 nncon=mxepg+1; 122 nodecon=xNew Init<int>(mncon*nncon,0);122 nodecon=xNewZeroInit<int>(mncon*nncon); 123 123 ncfree=true; 124 124 … … 150 150 else if (mdata == mncon) { 151 151 _printf_(true,"Averaging nodal data to element data.\n"); 152 edata=xNew Init<double>(melem*ndata,0);152 edata=xNewZeroInit<double>(melem*ndata); 153 153 edfree=true; 154 154 -
issm/trunk-jpl/src/c/modules/Krigingx/pKrigingx.cpp
r12442 r12446 37 37 38 38 /*Allocate output*/ 39 predictions =xNew Init<double>(n_interp,0.0);40 error =xNew Init<double>(n_interp,0.0);39 predictions =xNewZeroInit<double>(n_interp); 40 error =xNewZeroInit<double>(n_interp); 41 41 42 42 /*Get output*/ -
issm/trunk-jpl/src/c/objects/DakotaPlugin.cpp
r12354 r12446 85 85 86 86 /*Initialize responses: */ 87 responses=xNew Init<IssmDouble>(numFns,0.0);87 responses=xNewZeroInit<IssmDouble>(numFns); 88 88 89 89 /*run core solution: */ -
issm/trunk-jpl/src/c/objects/Numerics/ElementMatrix.cpp
r12441 r12446 101 101 /*Gset and values*/ 102 102 this->gglobaldoflist=xNew<int>(this->nrows); 103 this->values=xNew Init<double>(this->nrows*this->ncols,0.0);103 this->values=xNewZeroInit<double>(this->nrows*this->ncols); 104 104 for(i=0;i<Ke1->nrows;i++){ 105 105 for(j=0;j<Ke1->ncols;j++){ … … 205 205 206 206 /*fill values with 0: */ 207 this->values=xNew Init<double>(this->nrows*this->ncols,0.0);207 this->values=xNewZeroInit<double>(this->nrows*this->ncols); 208 208 209 209 /*g list*/ -
issm/trunk-jpl/src/c/objects/Numerics/ElementVector.cpp
r12441 r12446 75 75 /*Gset and values*/ 76 76 this->gglobaldoflist=xNew<int>(this->nrows); 77 this->values=xNew Init<double>(this->nrows,0.0);77 this->values=xNewZeroInit<double>(this->nrows); 78 78 for(i=0;i<pe1->nrows;i++){ 79 79 this->values[i] += pe1->values[i]; … … 138 138 139 139 /*fill values with 0: */ 140 this->values=xNew Init<double>(this->nrows,0.0);140 this->values=xNewZeroInit<double>(this->nrows); 141 141 142 142 /*g list*/ -
issm/trunk-jpl/src/c/shared/Alloc/xNewDelete.h
r12353 r12446 8 8 #include <cassert> 9 9 10 11 // memory management of types 12 // T with non-trivial constructors require 13 // C++ style memory management 14 #define USE_CXX_MEMORY_MANAGMENT_FOR_NON_POD_TYPES 15 // but for speed on may alternatively use C memory managment 16 // but can do so safely only for T that are at most 17 // plain old data structures (POD) 18 #ifndef USE_CXX_MEMORY_MANAGMENT_FOR_NON_POD_TYPES 19 #include <cstdlib> 20 #endif 21 10 22 template <class T> 11 23 T* xNew(unsigned int size) { 24 #ifdef USE_CXX_MEMORY_MANAGMENT_FOR_NON_POD_TYPES 12 25 T* aT_p=new T[size]; 13 26 assert(aT_p); 14 27 return aT_p; 15 }; 28 #else 29 T* aT_p=(T*)malloc(size*sizeof(T)); 30 assert(aT_p); 31 return aT_p; 32 #endif 33 } 16 34 17 35 template <class T> 18 T* xNewInit(unsigned int size, const T initVal) { 19 T* aT_p=new T[size]; 36 T* xNewZeroInit(unsigned int size) { 37 #ifdef USE_CXX_MEMORY_MANAGMENT_FOR_NON_POD_TYPES 38 T* aT_p=xNew<T>(size); 39 for (unsigned int i=0; i<size;++i) 40 aT_p[i]=(T)0; 41 return aT_p; 42 #else 43 T* aT_p=(T*)calloc(size,sizeof(T)); 20 44 assert(aT_p); 21 for (int i=0; i<size;++i)22 aT_p[i]=initVal;23 45 return aT_p; 24 }; 46 #endif 47 } 25 48 26 49 template <class T> 27 50 void xDelete(T*& aT_p) { 28 51 if (aT_p) 52 #ifdef USE_CXX_MEMORY_MANAGMENT_FOR_NON_POD_TYPES 29 53 delete []aT_p; 54 #else 55 free((void*)aT_p); 56 #endif 30 57 aT_p=0; 31 }; 58 } 59 60 template <class T> 61 T* xReNew(T* old, unsigned int size) { 62 #ifdef USE_CXX_MEMORY_MANAGMENT_FOR_NON_POD_TYPES 63 assert(old); 64 T* aT_p=xNew<T>(size); 65 for (unsigned int i=0; i<size;++i) 66 aT_p[i]=old[i]; 67 xDelete<T>(old); 68 return aT_p; 69 #else 70 T* aT_p=(T*)realloc((void*)old,size*sizeof(T)); 71 assert(aT_p); 72 return aT_p; 73 #endif 74 } 32 75 33 76 #endif -
issm/trunk-jpl/src/c/shared/TriMesh/SplitMeshForRifts.cpp
r12440 r12446 52 52 53 53 /*Go through all nodes of the rift segments, and start splitting the mesh: */ 54 flags=xNew Init<int>(nods,0); //to make sure we don't split the same nodes twice!54 flags=xNewZeroInit<int>(nods); //to make sure we don't split the same nodes twice! 55 55 for (i=0;i<nriftsegs;i++){ 56 56 for (j=0;j<2;j++){ -
issm/trunk-jpl/src/c/shared/TriMesh/TriMeshUtils.cpp
r12440 r12446 66 66 else{ 67 67 /*Reallocate another max_number_elements slots in the GridElements: */ 68 GridElementsRealloc= (int*)xrealloc(GridElements,(current_size+max_number_elements)*sizeof(int));68 GridElementsRealloc=xReNew<int>(GridElements,(current_size+max_number_elements)); 69 69 if (!GridElementsRealloc){ 70 70 noerr=0; … … 129 129 130 130 /*Allocate segmentflags: */ 131 riftsegments_uncompressed=xNew Init<int>(nsegs*5,0);131 riftsegments_uncompressed=xNewZeroInit<int>(nsegs*5); 132 132 133 133 /*Find the segments that belong to a rift: they are the ones that see two elements. The other ones belong to a boundary … … 905 905 906 906 /*allocate riftpenaltypairs, and riftnumpenaltypairs: */ 907 if((numsegs/2-1)!=0)riftpenaltypairs=xNew Init<double>((numsegs/2-1)*RIFTPENALTYPAIRSWIDTH,0.0);907 if((numsegs/2-1)!=0)riftpenaltypairs=xNewZeroInit<double>((numsegs/2-1)*RIFTPENALTYPAIRSWIDTH); 908 908 909 909 /*Go through only one flank of the rifts, not counting the tips: */ -
issm/trunk-jpl/src/c/toolkits/issm/SeqMat.cpp
r12429 r12446 33 33 this->N=pN; 34 34 this->matrix=NULL; 35 if(M*N) this->matrix=xNew Init<double>(pM*pN,0.0);35 if(M*N) this->matrix=xNewZeroInit<double>(pM*pN); 36 36 } 37 37 /*}}}*/ … … 42 42 this->N=pN; 43 43 this->matrix=NULL; 44 if(M*N) this->matrix=xNew Init<double>(pM*pN,0.0);44 if(M*N) this->matrix=xNewZeroInit<double>(pM*pN); 45 45 } 46 46 /*}}}*/ … … 54 54 this->matrix=NULL; 55 55 if(M*N){ 56 this->matrix=xNew Init<double>(pM*pN,0.0);56 this->matrix=xNewZeroInit<double>(pM*pN); 57 57 memcpy(this->matrix,serial_mat,pM*pN*sizeof(double)); 58 58 } … … 66 66 this->N=pN; 67 67 this->matrix=NULL; 68 if(M*N) this->matrix=xNew Init<double>(pM*pN,0.0);68 if(M*N) this->matrix=xNewZeroInit<double>(pM*pN); 69 69 } 70 70 /*}}}*/ -
issm/trunk-jpl/src/c/toolkits/issm/SeqVec.cpp
r12429 r12446 31 31 this->M=pM; 32 32 this->vector=NULL; 33 if(this->M) this->vector=xNew Init<double>(pM,0.0);33 if(this->M) this->vector=xNewZeroInit<double>(pM); 34 34 } 35 35 /*}}}*/ … … 42 42 this->vector=NULL; 43 43 if(this->M){ 44 this->vector=xNew Init<double>(pM,0.0);44 this->vector=xNewZeroInit<double>(pM); 45 45 memcpy(this->vector,buffer,pM*sizeof(double)); 46 46 }
Note:
See TracChangeset
for help on using the changeset viewer.