Parcourir la source

minor changes

Dhairya Malhotra il y a 8 ans
Parent
commit
9338003641

+ 2 - 1
include/pvfmm/common.hpp

@@ -6,7 +6,8 @@
 #define NULL 0
 #endif
 
-#include <stdint.h>
+#include <cstddef>
+#include <cstdint>
 namespace pvfmm {
 typedef long Integer;  // bounded numbers < 32k
 typedef int64_t Long;  // problem size

+ 4 - 0
include/pvfmm/intrin_wrapper.hpp

@@ -1,6 +1,10 @@
 #ifndef _PVFMM_INTRIN_WRAPPER_HPP_
 #define _PVFMM_INTRIN_WRAPPER_HPP_
 
+#include <pvfmm/math_utils.hpp>
+#include <pvfmm/common.hpp>
+#include <cstdint>
+
 #ifdef __SSE__
 #include <xmmintrin.h>
 #endif

+ 2 - 2
include/pvfmm/mat_utils.hpp

@@ -10,13 +10,13 @@ template <class T> void gemm(char TransA, char TransB, int M, int N, int K, T al
 
 template <class T> void cublasgemm(char TransA, char TransB, int M, int N, int K, T alpha, T *A, int lda, T *B, int ldb, T beta, T *C, int ldc);
 
-template <class T> void svd(char *JOBU, char *JOBVT, int *M, int *N, T *A, int *LDA, T *S, T *U, int *LDU, T *VT, int *LDVT, T *WORK, int *LWORK, int *INFO);
+template <class T> void svd(char *JOBU, char *JOBVT, int *M, int *N, Iterator<T> A, int *LDA, Iterator<T> S, Iterator<T> U, int *LDU, Iterator<T> VT, int *LDVT, Iterator<T> WORK, int *LWORK, int *INFO);
 
 /**
  * \brief Computes the pseudo inverse of matrix M(n1xn2) (in row major form)
  * and returns the output M_(n2xn1).
  */
-template <class T> void pinv(T *M, int n1, int n2, T eps, T *M_);
+template <class T> void pinv(Iterator<T> M, int n1, int n2, T eps, Iterator<T> M_);
 
 }  // end namespace mat
 }  // end namespace pvfmm

+ 2 - 0
include/pvfmm/math_utils.hpp

@@ -1,6 +1,8 @@
 #ifndef _MATH_UTILS_
 #define _MATH_UTILS_
 
+#include <pvfmm/common.hpp>
+
 #include <cmath>
 #include <ostream>
 

+ 2 - 3
include/pvfmm/matrix.hpp

@@ -1,7 +1,7 @@
 #ifndef _PVFMM_MATRIX_HPP_
 #define _PVFMM_MATRIX_HPP_
 
-#include <stdint.h>
+#include <cstdint>
 #include <cstdlib>
 
 #include <pvfmm/common.hpp>
@@ -90,7 +90,6 @@ template <class ValueType> std::ostream& operator<<(std::ostream& output, const
  * perm := [p1 p2 ... pn] is the permutation vector,
  * scal := [s1 s2 ... sn] is the scaling vector.
  */
-#define PERM_INT_T Long
 template <class ValueType> class Permutation {
 
  public:
@@ -110,7 +109,7 @@ template <class ValueType> class Permutation {
 
   Matrix<ValueType> operator*(const Matrix<ValueType>& M);
 
-  Vector<PERM_INT_T> perm;
+  Vector<Long> perm;
   Vector<ValueType> scal;
 };
 

+ 4 - 4
include/pvfmm/matrix.txx

@@ -388,7 +388,7 @@ template <class ValueType> void Matrix<ValueType>::SVD(Matrix<ValueType>& tU, Ma
   wssize = (wssize > wssize1 ? wssize : wssize1);
 
   Iterator<ValueType> wsbuf = aligned_new<ValueType>(wssize);
-  pvfmm::mat::svd(&JOBU, &JOBVT, &m, &n, &M[0][0], &m, &tS[0][0], &tVT[0][0], &m, &tU[0][0], &k, wsbuf, &wssize, &INFO);
+  pvfmm::mat::svd(&JOBU, &JOBVT, &m, &n, M.Begin(), &m, tS.Begin(), tVT.Begin(), &m, tU.Begin(), &k, wsbuf, &wssize, &INFO);
   aligned_delete<ValueType>(wsbuf);
 
   if (INFO != 0) std::cout << INFO << '\n';
@@ -460,7 +460,7 @@ template <class ValueType> Permutation<ValueType> Permutation<ValueType>::Transp
   Long size = perm.Dim();
   Permutation<ValueType> P_r(size);
 
-  Vector<PERM_INT_T>& perm_r = P_r.perm;
+  Vector<Long>& perm_r = P_r.perm;
   Vector<ValueType>& scal_r = P_r.scal;
   for (Long i = 0; i < size; i++) {
     perm_r[perm[i]] = i;
@@ -474,7 +474,7 @@ template <class ValueType> Permutation<ValueType> Permutation<ValueType>::operat
   assert(P.Dim() == size);
 
   Permutation<ValueType> P_r(size);
-  Vector<PERM_INT_T>& perm_r = P_r.perm;
+  Vector<Long>& perm_r = P_r.perm;
   Vector<ValueType>& scal_r = P_r.scal;
   for (Long i = 0; i < size; i++) {
     perm_r[i] = perm[P.perm[i]];
@@ -507,7 +507,7 @@ template <class ValueType> Matrix<ValueType> operator*(const Matrix<ValueType>&
 
   Matrix<ValueType> M_r(d0, d1, NULL);
   for (Long i = 0; i < d0; i++) {
-    ConstIterator<PERM_INT_T> perm_ = P.perm.Begin();
+    ConstIterator<Long> perm_ = P.perm.Begin();
     ConstIterator<ValueType> scal_ = P.scal.Begin();
     ConstIterator<ValueType> M_ = M[i];
     Iterator<ValueType> M_r_ = M_r[i];

+ 4 - 2
include/pvfmm/mem_mgr.hpp

@@ -1,10 +1,9 @@
-// TODO: Implement fast stack allocation.
 #ifndef _PVFMM_MEM_MGR_HPP_
 #define _PVFMM_MEM_MGR_HPP_
 
 #include <omp.h>
 #include <cstdlib>
-#include <stdint.h>
+#include <cstdint>
 #include <cassert>
 #include <vector>
 #include <stack>
@@ -25,6 +24,8 @@ template <class ValueType> class ConstIterator {
 
   template <typename T> friend class Iterator;
 
+  void IteratorAssertChecks(Long j = 0) const;
+
  public:
   typedef std::random_access_iterator_tag iterator_category;
   typedef const ValueType& reference;
@@ -250,6 +251,7 @@ template <class ValueType, Long DIM> class StaticArray : public Iterator<ValueTy
   StaticArray& operator=(const StaticArray&);
 
   Iterator<ValueType> arr;
+  // ValueType arr_[DIM];
 };
 
 #define PVFMM_PTR2ITR(type, ptr, len) pvfmm::Iterator<type>((type*)ptr, len)

+ 16 - 7
include/pvfmm/mem_mgr.txx

@@ -22,7 +22,14 @@ template <class ValueType> inline ConstIterator<ValueType>::ConstIterator(const
     mem_head = NULL;
 }
 
-template <class ValueType> inline static void IteratorAssertChecks(Long offset, Long len, void* mem_head, Long alloc_ctr) {
+template <class ValueType> inline void ConstIterator<ValueType>::IteratorAssertChecks(Long j) const {
+  const auto& base = this->base;
+  const auto& offset = this->offset + j * (Long)sizeof(ValueType);
+  const auto& len = this->len;
+  const auto& mem_head = this->mem_head;
+  const auto& alloc_ctr = this->alloc_ctr;
+
+  if (*this == NULL) PVFMM_WARN("dereferencing a NULL pointer is undefined.");
   PVFMM_ASSERT_MSG(offset >= 0 && offset + (Long)sizeof(ValueType) <= len, "access to pointer [B" << (offset < 0 ? "" : "+") << offset << ",B" << (offset + (Long)sizeof(ValueType) < 0 ? "" : "+") << offset + (Long)sizeof(ValueType) << ") is outside of the range [B,B+" << len << ").");
   if (mem_head) {
     MemoryManager::MemHead& mh = *(MemoryManager::MemHead*)(mem_head);
@@ -31,37 +38,38 @@ template <class ValueType> inline static void IteratorAssertChecks(Long offset,
 }
 
 template <class ValueType> inline typename ConstIterator<ValueType>::reference ConstIterator<ValueType>::operator*() const {
-  IteratorAssertChecks<ValueType>(this->offset, this->len, this->mem_head, this->alloc_ctr);
+  this->IteratorAssertChecks();
   return *(ValueType*)(base + offset);
 }
 
 template <class ValueType> inline const typename ConstIterator<ValueType>::value_type* ConstIterator<ValueType>::operator->() const {
-  IteratorAssertChecks<ValueType>(this->offset, this->len, this->mem_head, this->alloc_ctr);
+  this->IteratorAssertChecks();
   return (ValueType*)(base + offset);
 }
 
 template <class ValueType> inline typename ConstIterator<ValueType>::reference ConstIterator<ValueType>::operator[](difference_type j) const {
-  IteratorAssertChecks<ValueType>(this->offset + j * (Long)sizeof(ValueType), this->len, this->mem_head, this->alloc_ctr);
+  this->IteratorAssertChecks(j);
   return *(ValueType*)(base + offset + j * (Long)sizeof(ValueType));
 }
 
 template <class ValueType> inline typename Iterator<ValueType>::reference Iterator<ValueType>::operator*() const {
-  IteratorAssertChecks<ValueType>(this->offset, this->len, this->mem_head, this->alloc_ctr);
+  this->IteratorAssertChecks();
   return *(ValueType*)(this->base + this->offset);
 }
 
 template <class ValueType> inline typename Iterator<ValueType>::value_type* Iterator<ValueType>::operator->() const {
-  IteratorAssertChecks<ValueType>(this->offset, this->len, this->mem_head, this->alloc_ctr);
+  this->IteratorAssertChecks();
   return (ValueType*)(this->base + this->offset);
 }
 
 template <class ValueType> inline typename Iterator<ValueType>::reference Iterator<ValueType>::operator[](difference_type j) const {
-  IteratorAssertChecks<ValueType>(this->offset + j * (Long)sizeof(ValueType), this->len, this->mem_head, this->alloc_ctr);
+  this->IteratorAssertChecks(j);
   return *(ValueType*)(this->base + this->offset + j * (Long)sizeof(ValueType));
 }
 
 template <class ValueType, Long DIM> inline StaticArray<ValueType, DIM>::StaticArray() {
   arr = aligned_new<ValueType>(DIM);
+  // arr = PVFMM_PTR2ITR(ValueType, arr_, DIM);
   Iterator<ValueType>::operator=(arr);
 }
 
@@ -69,6 +77,7 @@ template <class ValueType, Long DIM> inline StaticArray<ValueType, DIM>::~Static
 
 template <class ValueType, Long DIM> inline StaticArray<ValueType, DIM>::StaticArray(const StaticArray& I) {
   arr = aligned_new<ValueType>(DIM);
+  // arr = PVFMM_PTR2ITR(ValueType, arr_, DIM);
   Iterator<ValueType>::operator=(arr);
   for (Long i = 0; i < DIM; i++) (*this)[i] = I[i];
 }

+ 34 - 21
include/pvfmm/profile.txx

@@ -139,16 +139,23 @@ inline void Profile::print(const Comm* comm_) {
   size_t level = 0;
   if (!rank && prof.e_log.size() > 0) {
     std::cout << "\n" << std::setw(width * 3 - 2 * level) << " ";
-    std::cout << "  " << std::setw(width) << "t_min";
-    std::cout << "  " << std::setw(width) << "t_avg";
-    std::cout << "  " << std::setw(width) << "t_max";
-    std::cout << "  " << std::setw(width) << "f_min";
-    std::cout << "  " << std::setw(width) << "f_avg";
-    std::cout << "  " << std::setw(width) << "f_max";
+    if (np == 1) {
+      std::cout << "  " << std::setw(width) << "t";
+      std::cout << "  " << std::setw(width) << "f";
+      std::cout << "  " << std::setw(width) << "f/s";
+    } else {
+      std::cout << "  " << std::setw(width) << "t_min";
+      std::cout << "  " << std::setw(width) << "t_avg";
+      std::cout << "  " << std::setw(width) << "t_max";
+
+      std::cout << "  " << std::setw(width) << "f_min";
+      std::cout << "  " << std::setw(width) << "f_avg";
+      std::cout << "  " << std::setw(width) << "f_max";
 
-    std::cout << "  " << std::setw(width) << "f/s_min";
-    std::cout << "  " << std::setw(width) << "f/s_max";
-    std::cout << "  " << std::setw(width) << "f/s_total";
+      std::cout << "  " << std::setw(width) << "f/s_min";
+      std::cout << "  " << std::setw(width) << "f/s_max";
+      std::cout << "  " << std::setw(width) << "f/s_total";
+    }
 
     std::cout << "  " << std::setw(width) << "m_init";
     std::cout << "  " << std::setw(width) << "m_max";
@@ -221,18 +228,24 @@ inline void Profile::print(const Comm* comm_) {
         ss << "+-";
         ss << std::setw(width * 3 - 2 * level) << prof.n_log[i];
         ss << std::setiosflags(std::ios::right);
-        ss << "  " << std::setw(width) << t_min;
-        ss << "  " << std::setw(width) << t_avg;
-        ss << "  " << std::setw(width) << t_max;
-
-        ss << "  " << std::setw(width) << f_min;
-        ss << "  " << std::setw(width) << f_avg;
-        ss << "  " << std::setw(width) << f_max;
-
-        ss << "  " << std::setw(width) << fs_min;
-        // ss<<"  "<<std::setw(width)<<fs_avg;
-        ss << "  " << std::setw(width) << fs_max;
-        ss << "  " << std::setw(width) << fs_sum;
+        if (np == 1) {
+          ss << "  " << std::setw(width) << t_avg;
+          ss << "  " << std::setw(width) << f_avg;
+          ss << "  " << std::setw(width) << fs_sum;
+        } else {
+          ss << "  " << std::setw(width) << t_min;
+          ss << "  " << std::setw(width) << t_avg;
+          ss << "  " << std::setw(width) << t_max;
+
+          ss << "  " << std::setw(width) << f_min;
+          ss << "  " << std::setw(width) << f_avg;
+          ss << "  " << std::setw(width) << f_max;
+
+          ss << "  " << std::setw(width) << fs_min;
+          // ss<<"  "<<std::setw(width)<<fs_avg;
+          ss << "  " << std::setw(width) << fs_max;
+          ss << "  " << std::setw(width) << fs_sum;
+        }
 
         ss << "  " << std::setw(width) << m_init;
         ss << "  " << std::setw(width) << m_max;

+ 1 - 1
include/pvfmm/vector.hpp

@@ -5,7 +5,7 @@
 
 #include <vector>
 #include <cstdlib>
-#include <stdint.h>
+#include <cstdint>
 
 namespace pvfmm {
 

+ 1 - 1
src/test.cpp

@@ -74,7 +74,7 @@ int main(int argc, char** argv) {
   {  // Test out-of-bound writes
     pvfmm::Iterator<char> A = pvfmm::aligned_new<char>(10);
     A[9];
-    A[10];  // Should print stack tace here (in debug mode).
+    A[10];  // Should print stack trace here (in debug mode).
     // pvfmm::aligned_delete(A); // Show memory leak warning when commented
   }