kspaceFirstOrder3D-OMP 1.0
The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
MatrixClasses/BaseFloatMatrix.cpp
Go to the documentation of this file.
00001 
00034 #include <string.h>
00035 #include <malloc.h>
00036 #include <assert.h>
00037 
00038 #include <MatrixClasses/BaseFloatMatrix.h>
00039 
00040 #include <Utils/DimensionSizes.h>
00041 #include <Utils/ErrorMessages.h>
00042 
00043 
00044 //----------------------------------------------------------------------------//
00045 //                              Constants                                     //
00046 //----------------------------------------------------------------------------//
00047 
00048 //----------------------------------------------------------------------------//
00049 //                              Definitions                                   //
00050 //----------------------------------------------------------------------------//
00051 
00052 //----------------------------------------------------------------------------//
00053 //                              Implementation                                //
00054 //                              public methods                                //
00055 //----------------------------------------------------------------------------//
00056 
00057   
00065 void TBaseFloatMatrix::CopyData(TBaseFloatMatrix & src){
00066         
00067     memcpy(pMatrixData,src.pMatrixData,sizeof(float)*pTotalAllocatedElementCount);
00068         
00069 }// end of CopyDataSameSize
00070 //------------------------------------------------------------------------------
00071 
00072 
00078 void TBaseFloatMatrix::ZeroMatrix(){
00079 
00080 #ifndef __NO_OMP__    
00081     #pragma omp parallel for schedule (static)
00082 #endif
00083     for (size_t i=0; i < pTotalAllocatedElementCount; i++){
00084         pMatrixData[i] = 0.0f;
00085     }
00086     
00087 }// end of ZeroMatrix
00088 //------------------------------------------------------------------------------
00089 
00090 
00096 void TBaseFloatMatrix::ScalarDividedBy(const float  scalar){
00097 #ifndef __NO_OMP__      
00098     #pragma omp parallel for schedule (static)
00099 #endif
00100     for (size_t i=0; i < pTotalAllocatedElementCount; i++){
00101         pMatrixData[i] = scalar / pMatrixData[i];
00102         
00103     }
00104 }// end of ScalarDividedBy
00105 //------------------------------------------------------------------------------
00106 
00107 
00108 
00109 //----------------------------------------------------------------------------//
00110 //                              Implementation                                //
00111 //                             protected methods                              //
00112 //----------------------------------------------------------------------------//
00113 
00118 void TBaseFloatMatrix::AllocateMemory(){
00119     /* No memory allocated before this function*/
00120     assert(pMatrixData == NULL);
00121     
00122     pMatrixData = ( float *) memalign(SSE_ALIGNMENT,pTotalAllocatedElementCount * sizeof (float));
00123     
00124     if (!pMatrixData) {
00125         fprintf(stderr,Matrix_ERR_FMT_NotEnoughMemory, "TBaseFloatMatrix");
00126         throw bad_alloc();
00127     }
00128     
00129     ZeroMatrix();
00130     
00131 }// end of AllocateMemory
00132 //------------------------------------------------------------------------------
00133 
00137  void TBaseFloatMatrix::FreeMemory(){
00138      
00139     if (pMatrixData) free(pMatrixData);
00140          
00141     pMatrixData = NULL;
00142 
00143 }// end of MemoryDealocation      
00144 //------------------------------------------------------------------------------
00145 
00146 
00147 //----------------------------------------------------------------------------//
00148 //                              Implementation                                //
00149 //                              private methods                               //
00150 //----------------------------------------------------------------------------//
 All Classes Files Functions Variables Typedefs Enumerations