Commits

Anonymous committed 5121a44

cleaning up the new code

Comments (0)

Files changed (3)

 
 /* void *m4ri_mm_calloc( int count, int size ); */
 static inline void *m4ri_mm_calloc( int count, int size ) {
+#ifdef HAVE_OPENMP
+#pragma omp critical
+{
+#endif
+
 #ifdef HAVE_MM_MALLOC
   void *newthing = _mm_malloc(count*size, 16);
 #else
   void *newthing = calloc(count, size);
 #endif
+
+#ifdef HAVE_OPENMP
+ }
+#endif
+
   if (newthing==NULL) {
     m4ri_die("m4ri_mm_calloc: calloc returned NULL\n");
     return NULL; /* unreachable. */
 
 /* void *m4ri_mm_malloc( int size ); */
 static inline void *m4ri_mm_malloc( int size ) {
+#ifdef HAVE_OPENMP
+#pragma omp critical
+{
+#endif
+
 #ifdef HAVE_MM_MALLOC
   void *newthing = _mm_malloc(size, 16);
 #else
   void *newthing=malloc( size );
 #endif  
+#ifdef HAVE_OPENMP
+ }
+#endif
   if (newthing==NULL && (size>0)) {
     m4ri_die("m4ri_mm_malloc: malloc returned NULL\n");
     return NULL; /* unreachable */
 
 /* void m4ri_mm_free(void *condemned, ...); */
 static inline void m4ri_mm_free(void *condemned, ...) { 
+#ifdef HAVE_OPENMP
+#pragma omp critical
+{
+#endif
 #ifdef HAVE_MM_MALLOC
   _mm_free(condemned); 
 #else
   free(condemned);
 #endif  
+#ifdef HAVE_OPENMP
+ }
+#endif
 }
 
 /**
  */
 
 static inline void *m4ri_mmc_malloc(size_t size) {
+#ifdef HAVE_OPENMP
+#pragma omp critical
+{
+#endif
 #ifdef ENABLE_MMC
   mmb_t *mm = m4ri_mmc_handle();
   if (size <= M4RI_MMC_THRESHOLD) {
     }
   }
 #endif //ENABLE_MMC
+#ifdef HAVE_OPENMP
+ }
+#endif
   return m4ri_mm_malloc(size);
 }
 
  */
 
 static inline void m4ri_mmc_free(void *condemned, size_t size) {
+#ifdef HAVE_OPENMP
+#pragma omp critical
+{
+#endif
 #ifdef ENABLE_MMC
   static size_t j = 0;
   mmb_t *mm = m4ri_mmc_handle();
     return;
   }
 #endif //ENABLE_MMC
+#ifdef HAVE_OPENMP
+ }
+#endif
   m4ri_mm_free(condemned);
 }
 
  */
 
 static inline void m4ri_mmc_cleanup(void) {
+#ifdef HAVE_OPENMP
+#pragma omp critical
+{
+#endif
   mmb_t *mm = m4ri_mmc_handle();
   size_t i;
   for(i=0; i < M4RI_MMC_NBLOCKS; i++) {
       m4ri_mm_free(mm[i].data);
     mm[i].size = 0;
   }
+#ifdef HAVE_OPENMP
+ }
+#endif
 }
 
 #endif //MISC_H

src/packedmatrix.c

   mzd_t *A;
   size_t i,j;
 
-#ifdef HAVE_OPENMP
-#pragma omp critical
-{
-#endif
   A=(mzd_t *)m4ri_mmc_malloc(sizeof(mzd_t));
-#ifdef HAVE_OPENMP
- }
-#endif
 
   A->width=DIV_CEIL(c,RADIX);
 
   A->nrows=r;
   A->offset = 0;
 
-#ifdef HAVE_OPENMP
-#pragma omp critical
-{
-#endif
-  A->rows=(word **)m4ri_mmc_malloc( r * sizeof(word*) );
-#ifdef HAVE_OPENMP
- }
-#endif
+  A->rows=(word **)m4ri_mmc_calloc( sizeof(word*), r+1); //we're overcomitting here
 
-
-#ifdef HAVE_OPENMP
-#pragma omp critical
-{
-#endif
-
-  if(A->width) {
+  if(r && c) {
     /* we allow more than one malloc call so he have to be a bit clever
        here */
     
     for(j=0; j<rest; j++) {
       A->rows[max_rows_per_block*(nblocks-1) + j] = (word*)(A->blocks[nblocks-1].data) + j*A->width;
     }
+  } else {
+    A->blocks = NULL;
   }
-#ifdef HAVE_OPENMP
- }
-#endif
-
 
 #ifdef HAVE_SSE2
   if (incw) {
 mzd_t *mzd_init_window (const mzd_t *m, size_t lowr, size_t lowc, size_t highr, size_t highc) {
   size_t nrows, ncols, i, offset; 
   mzd_t *window;
-#ifdef HAVE_OPENMP
-#pragma omp critical
-{
-#endif
   window = (mzd_t *)m4ri_mmc_malloc(sizeof(mzd_t));
-#ifdef HAVE_OPENMP
-}
-#endif
+
   nrows = MIN(highr - lowr, m->nrows - lowr);
   ncols = highc - lowc;
   
   if ((window->offset + ncols) % RADIX)
     window->width++;
   window->blocks = NULL;
-  window->blocksizes = NULL;
 
-#ifdef HAVE_OPENMP
-#pragma omp critical
-{
-#endif
-  window->rows = (word **)m4ri_mmc_malloc( nrows * sizeof(word*));
-#ifdef HAVE_OPENMP
-}
-#endif
+  if(nrows)
+    window->rows = (word **)m4ri_mmc_malloc( nrows * sizeof(word*));
+  else
+    window->rows = NULL;
+
   for(i=0; i<nrows; i++) {
     window->rows[i] = m->rows[lowr + i] + offset;
   }
 
 
 void mzd_free( mzd_t *A) {
-#ifdef HAVE_OPENMP
-#pragma omp critical
-{
-#endif
-  m4ri_mmc_free(A->rows, A->nrows * sizeof(word*));
-  if(A->width && A->blocks) {
+  if(A->rows)
+    m4ri_mmc_free(A->rows, (A->nrows+1) * sizeof(word*));
+  if(A->blocks) {
     size_t i;
     for(i=0; A->blocks[i].size; i++) {
       m4ri_mmc_free(A->blocks[i].data, A->blocks[i].size);
     m4ri_mmc_free(A->blocks, (i+1) * sizeof(mmb_t));
   }
   m4ri_mmc_free(A, sizeof(mzd_t));
-#ifdef HAVE_OPENMP
-}
-#endif
-}
-
-void mzd_free_window( mzd_t *A) {
-#ifdef HAVE_OPENMP
-#pragma omp critical
-{
-#endif
-  m4ri_mmc_free(A->rows, A->nrows * sizeof(word*));
-  m4ri_mmc_free(A, sizeof(mzd_t));
-#ifdef HAVE_OPENMP
-}
-#endif
 }
 
 void mzd_print( const mzd_t *M ) {

src/packedmatrix.h

   mmb_t *blocks;
 
   /**
-   * Size of each block in bytes.
-   */
-
-  size_t *blocksizes;
-
-  /**
    * Number of rows.
    */
 
  * \param A Matrix
  */
 
-void mzd_free_window(mzd_t *A);
+#define mzd_free_window mzd_free
 
 /**
  * \brief Swap the two rows rowa and rowb.