Parcourir la source

Add .clang-format

Dhairya Malhotra il y a 8 ans
Parent
commit
97c77e2795
8 fichiers modifiés avec 73 ajouts et 36 suppressions
  1. 38 0
      .clang-format
  2. 2 3
      Makefile
  3. 4 6
      include/pvfmm.hpp
  4. 0 1
      include/pvfmm/comm.hpp
  5. 11 7
      include/pvfmm/comm.txx
  6. 0 1
      include/pvfmm/common.hpp
  7. 3 3
      include/pvfmm/mat_utils.txx
  8. 15 15
      src/test.cpp

+ 38 - 0
.clang-format

@@ -0,0 +1,38 @@
+BasedOnStyle: LLVM
+ContinuationIndentWidth: 8
+
+BasedOnStyle: Google
+AccessModifierOffset: -1
+AlignEscapedNewlinesLeft: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortIfStatementsOnASingleLine: true
+AllowShortLoopsOnASingleLine: true
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackParameters: true
+BreakBeforeBinaryOperators: true
+BreakBeforeBraces: Attach
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: true
+ColumnLimit: 1000
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
+ConstructorInitializerIndentWidth: 2
+Cpp11BracedListStyle: true
+DerivePointerBinding: true
+IndentCaseLabels: true
+IndentFunctionDeclarationAfterType: true
+IndentWidth: 2
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+PointerBindsToType: true
+SpaceAfterControlStatementKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 2
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInAngles:  false
+Standard: Cpp11
+TabWidth: 2
+UseTab: Never

+ 2 - 3
Makefile

@@ -2,12 +2,12 @@
 CXX=icpc
 CXXFLAGS = -std=c++11 -fopenmp -O3 # need C++11 and OpenMP
 
-# Optional flags
+#Optional flags
 CXXFLAGS += -DNDEBUG # release build
 CXXFLAGS += -g -rdynamic # for stack trace
 CXXFLAGS += -mkl -DPVFMM_HAVE_BLAS # use BLAS
 CXXFLAGS += -mkl -DPVFMM_HAVE_LAPACK # use LAPACK
-#CXXFLAGS += -DPVFMM_HAVE_MPI # use MPI
+#CXXFLAGS += -DPVFMM_HAVE_MPI #use MPI
 
 
 RM = rm -f
@@ -34,4 +34,3 @@ $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
 clean:
 	$(RM) -r $(BINDIR)/* $(OBJDIR)/*
 	$(RM) *~ */*~
-

+ 4 - 6
include/pvfmm.hpp

@@ -13,15 +13,13 @@
 #define PVFMM_MEM_ALIGN 64
 #define PVFMM_GLOBAL_MEM_BUFF 1024LL * 5LL  // in MB
 #ifndef NDEBUG
-#define PVFMM_MEMDEBUG // Enable memory checks.
+#define PVFMM_MEMDEBUG  // Enable memory checks.
 #endif
 
 // Profiling parameters
-#define PVFMM_PROFILE 5 // Granularity level
+#define PVFMM_PROFILE 5  // Granularity level
 #define PVFMM_VERBOSE
 
-
-
 // MPI Wrapper
 #include <pvfmm/comm.hpp>
 
@@ -45,6 +43,6 @@
 
 // Print stack trace
 #include <pvfmm/stacktrace.h>
-const int sgh = pvfmm::SetSigHandler(); // Set signal handler
+const int sgh = pvfmm::SetSigHandler();  // Set signal handler
 
-#endif //_PVFMM_HPP_
+#endif  //_PVFMM_HPP_

+ 0 - 1
include/pvfmm/comm.hpp

@@ -77,7 +77,6 @@ class Comm {
   template <class Type> void ScatterReverse(Vector<Type>& data_, const Vector<Long>& scatter_index_, Long loc_size_ = 0) const;
 
  private:
-
   template <typename A, typename B> struct SortPair {
     int operator<(const SortPair<A, B>& p1) const { return key < p1.key; }
     A key;

+ 11 - 7
include/pvfmm/comm.txx

@@ -102,8 +102,10 @@ template <class SType> void* Comm::Isend(ConstIterator<SType> sbuf, Long scount,
   return &request;
 #else
   auto it = recv_req.find(tag);
-  if (it == recv_req.end()) send_req.insert(std::pair<Integer,ConstIterator<char>>(tag,(ConstIterator<char>)sbuf));
-  else pvfmm::memcopy(it->second, (ConstIterator<char>)sbuf, scount * sizeof(SType));
+  if (it == recv_req.end())
+    send_req.insert(std::pair<Integer, ConstIterator<char>>(tag, (ConstIterator<char>)sbuf));
+  else
+    pvfmm::memcopy(it->second, (ConstIterator<char>)sbuf, scount * sizeof(SType));
   return NULL;
 #endif
 }
@@ -120,8 +122,10 @@ template <class RType> void* Comm::Irecv(Iterator<RType> rbuf, Long rcount, Inte
   return &request;
 #else
   auto it = send_req.find(tag);
-  if (it == send_req.end()) recv_req.insert(std::pair<Integer,Iterator<char>>(tag,(Iterator<char>)rbuf));
-  else pvfmm::memcopy((Iterator<char>)rbuf, it->second, rcount * sizeof(RType));
+  if (it == send_req.end())
+    recv_req.insert(std::pair<Integer, Iterator<char>>(tag, (Iterator<char>)rbuf));
+  else
+    pvfmm::memcopy((Iterator<char>)rbuf, it->second, rcount * sizeof(RType));
   return NULL;
 #endif
 }
@@ -222,7 +226,7 @@ template <class SType, class RType> void* Comm::Ialltoallv_sparse(ConstIterator<
   }
   return &request;
 #else
-  pvfmm::memcopy((Iterator<char>)(rbuf+rdispls[0]), (ConstIterator<char>)(sbuf+sdispls[0]), scounts[0] * sizeof(SType));
+  pvfmm::memcopy((Iterator<char>)(rbuf + rdispls[0]), (ConstIterator<char>)(sbuf + sdispls[0]), scounts[0] * sizeof(SType));
   return NULL;
 #endif
 }
@@ -266,9 +270,9 @@ template <class Type> void Comm::Alltoallv(ConstIterator<Type> sbuf, ConstIterat
     //#endif
   }
 
-  // TODO: implement hypercube scheme
+// TODO: implement hypercube scheme
 #else
-  pvfmm::memcopy((Iterator<char>)(rbuf+rdispls[0]), (ConstIterator<char>)(sbuf+sdispls[0]), scounts[0] * sizeof(Type));
+  pvfmm::memcopy((Iterator<char>)(rbuf + rdispls[0]), (ConstIterator<char>)(sbuf + sdispls[0]), scounts[0] * sizeof(Type));
 #endif
 }
 

+ 0 - 1
include/pvfmm/common.hpp

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

+ 3 - 3
include/pvfmm/mat_utils.txx

@@ -109,7 +109,7 @@ template <> inline void cublasgemm<double>(char TransA, char TransB, int M, int
 #define V(i, j) V_[(i) * dim[1] + (j)]
 //#define SVD_DEBUG
 
-template <class ValueType> static inline void GivensL(Iterator<ValueType> S_, StaticArray<Long,2>& dim, Long m, ValueType a, ValueType b) {
+template <class ValueType> static inline void GivensL(Iterator<ValueType> S_, StaticArray<Long, 2> &dim, Long m, ValueType a, ValueType b) {
   ValueType r = pvfmm::sqrt<ValueType>(a * a + b * b);
   ValueType c = a / r;
   ValueType s = -b / r;
@@ -126,7 +126,7 @@ template <class ValueType> static inline void GivensL(Iterator<ValueType> S_, St
   }
 }
 
-template <class ValueType> static inline void GivensR(Iterator<ValueType> S_, StaticArray<Long,2>& dim, Long m, ValueType a, ValueType b) {
+template <class ValueType> static inline void GivensR(Iterator<ValueType> S_, StaticArray<Long, 2> &dim, Long m, ValueType a, ValueType b) {
   ValueType r = pvfmm::sqrt<ValueType>(a * a + b * b);
   ValueType c = a / r;
   ValueType s = -b / r;
@@ -143,7 +143,7 @@ template <class ValueType> static inline void GivensR(Iterator<ValueType> S_, St
   }
 }
 
-template <class ValueType> static inline void SVD(StaticArray<Long,2>& dim, Iterator<ValueType> U_, Iterator<ValueType> S_, Iterator<ValueType> V_, ValueType eps = -1) {
+template <class ValueType> static inline void SVD(StaticArray<Long, 2> &dim, Iterator<ValueType> U_, Iterator<ValueType> S_, Iterator<ValueType> V_, ValueType eps = -1) {
   assert(dim[0] >= dim[1]);
 #ifdef SVD_DEBUG
   Matrix<ValueType> M0(dim[0], dim[1], S_);

+ 15 - 15
src/test.cpp

@@ -1,8 +1,8 @@
 #include "pvfmm.hpp"
 
-void ProfileMemgr(){
-  long N=5e5;
-  { // Without memory manager
+void ProfileMemgr() {
+  long N = 5e5;
+  {  // Without memory manager
     pvfmm::Profile::Tic("No-Memgr");
 
     pvfmm::Profile::Tic("Alloc");
@@ -11,7 +11,7 @@ void ProfileMemgr(){
 
     pvfmm::Profile::Tic("Array-Write");
 #pragma omp parallel for schedule(static)
-    for(long i=0;i<N;i++) A[i]=0;
+    for (long i = 0; i < N; i++) A[i] = 0;
     pvfmm::Profile::Toc();
 
     pvfmm::Profile::Tic("Free");
@@ -20,7 +20,7 @@ void ProfileMemgr(){
 
     pvfmm::Profile::Toc();
   }
-  { // With memory manager
+  {  // With memory manager
     pvfmm::Profile::Tic("With-Memgr");
 
     pvfmm::Profile::Tic("Alloc");
@@ -29,7 +29,7 @@ void ProfileMemgr(){
 
     pvfmm::Profile::Tic("Array-Write");
 #pragma omp parallel for schedule(static)
-    for(long i=0;i<N;i++) A[i]=0;
+    for (long i = 0; i < N; i++) A[i] = 0;
     pvfmm::Profile::Toc();
 
     pvfmm::Profile::Tic("Free");
@@ -40,18 +40,18 @@ void ProfileMemgr(){
   }
 }
 
-void TestMatrix(){
+void TestMatrix() {
   pvfmm::Profile::Tic("TestMatrix");
-  pvfmm::Matrix<double> M1(1000,1000);
-  pvfmm::Matrix<double> M2(1000,1000);
+  pvfmm::Matrix<double> M1(1000, 1000);
+  pvfmm::Matrix<double> M2(1000, 1000);
 
   pvfmm::Profile::Tic("Init");
-  for(long i=0;i<M1.Dim(0)*M1.Dim(1);i++) M1[0][i]=i;
-  for(long i=0;i<M2.Dim(0)*M2.Dim(1);i++) M2[0][i]=i*i;
+  for (long i = 0; i < M1.Dim(0) * M1.Dim(1); i++) M1[0][i] = i;
+  for (long i = 0; i < M2.Dim(0) * M2.Dim(1); i++) M2[0][i] = i * i;
   pvfmm::Profile::Toc();
 
   pvfmm::Profile::Tic("GEMM");
-  pvfmm::Matrix<double> M3=M1*M2;
+  pvfmm::Matrix<double> M3 = M1 * M2;
   pvfmm::Profile::Toc();
 
   pvfmm::Profile::Toc();
@@ -71,11 +71,11 @@ int main(int argc, char** argv) {
   // Print profiling results
   pvfmm::Profile::print();
 
-  { // Test out-of-bound writes
+  {  // 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).
-    //pvfmm::aligned_delete(A); // Show memory leak warning when commented
+    A[10];  // Should print stack tace here (in debug mode).
+    // pvfmm::aligned_delete(A); // Show memory leak warning when commented
   }
 
   return 0;