From daad7db726e88627fb0dafa04101d439cdbfdbe5 Mon Sep 17 00:00:00 2001
From: wfg <wfg@pc0098504.ornl.gov>
Date: Thu, 23 Feb 2017 13:34:17 -0500
Subject: [PATCH] Initial implementation of BPWriter and BP1Writer

Added -Wl,-rpath to Makefiles in DataMan examples
Added more variables to buildDataMan.sh
---
 buildDataMan.sh                       | 13 ++++++++++---
 examples/hello/datamanReader/Makefile |  4 ++--
 examples/hello/datamanWriter/Makefile |  4 ++--
 include/engine/bp/BPWriter.h          |  6 +++++-
 src/engine/bp/BPWriter.cpp            | 13 -------------
 src/format/BP1Writer.cpp              |  2 +-
 6 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/buildDataMan.sh b/buildDataMan.sh
index d629be60a..930c932fa 100755
--- a/buildDataMan.sh
+++ b/buildDataMan.sh
@@ -6,18 +6,25 @@
 #     Author: wfg
 
 DATAMAN_LOCATION=/home/wfg/Applications/DataMan
+MPICOMPILER=mpic++
+
+if [ "$(uname)" == "Darwin" ]; then
+	CCOMPILER=g++-6        
+elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
+	CCOMPILER=g++
+fi
 echo "######################################################################################"
 echo "Start building ADIOS ./lib/libadios.a ./libadios_nompi.a with DataMan library" 
 echo "######################################################################################"
 echo
-make HAVE_DATAMAN=yes DATAMAN_LOC=$DATAMAN_LOCATION       #build the ./lib/libadios.a and ./libadios_nompi.a
+make HAVE_DATAMAN=yes DATAMAN_LOC=$DATAMAN_LOCATION CC=$CCOMPILER MPICC=$MPICOMPILER       #build the ./lib/libadios.a and ./libadios_nompi.a
 echo
 echo "#################################################################"
 echo "Building Dataman Reader and Writer examples"
 echo "#################################################################"
-make -C ./examples/hello/datamanWriter HAVE_DATAMAN=yes DATAMAN_LOC=$DATAMAN_LOCATION
+make -C ./examples/hello/datamanWriter HAVE_DATAMAN=yes DATAMAN_LOC=$DATAMAN_LOCATION CC=$CCOMPILER MPICC=$MPICOMPILER
 echo
-make -C ./examples/hello/datamanReader HAVE_DATAMAN=yes DATAMAN_LOC=$DATAMAN_LOCATION
+make -C ./examples/hello/datamanReader HAVE_DATAMAN=yes DATAMAN_LOC=$DATAMAN_LOCATION CC=$CCOMPILER MPICC=$MPICOMPILER
 
 echo
 echo
diff --git a/examples/hello/datamanReader/Makefile b/examples/hello/datamanReader/Makefile
index bf33bdcab..57af50503 100644
--- a/examples/hello/datamanReader/Makefile
+++ b/examples/hello/datamanReader/Makefile
@@ -20,8 +20,8 @@ INC+= -I$(ADIOS_DIR)/include
 #DATAMAN
 DATAMAN_LOC=/home/wfg/Applications/DataMan
 INC+= -I$(DATAMAN_LOC)/include
-LIB+= -L$(DATAMAN_LOC)/lib -ldataman # -lcacheman -lstreamman -lzmqman
-LIB_NOMPI+= -L$(DATAMAN_LOC)/lib -ldataman
+LIB+= -Wl,-rpath=$(DATAMAN_LOC)/lib -L$(DATAMAN_LOC)/lib -ldataman # -lcacheman -lstreamman -lzmqman
+LIB_NOMPI+= -Wl,-rpath=$(DATAMAN_LOC)/lib -L$(DATAMAN_LOC)/lib -ldataman
 
 #COMPILER FLAGS
 CFLAGS=-Wall -O0 -g -Wpedantic -std=c++11
diff --git a/examples/hello/datamanWriter/Makefile b/examples/hello/datamanWriter/Makefile
index 195afdfbf..df793b9b6 100644
--- a/examples/hello/datamanWriter/Makefile
+++ b/examples/hello/datamanWriter/Makefile
@@ -20,8 +20,8 @@ INC+= -I$(ADIOS_DIR)/include
 #DATAMAN
 DATAMAN_LOC=/home/wfg/Applications/DataMan
 INC+= -I$(DATAMAN_LOC)/include
-LIB+= -L$(DATAMAN_LOC)/lib -ldataman # -lcacheman -lstreamman -lzmqman
-LIB_NOMPI+= -L$(DATAMAN_LOC)/lib -ldataman # -lcacheman -lstreamman -lzmqman
+LIB+= -Wl,-rpath=$(DATAMAN_LOC)/lib -L$(DATAMAN_LOC)/lib -ldataman # -lcacheman -lstreamman -lzmqman
+LIB_NOMPI+= -Wl,-rpath=$(DATAMAN_LOC)/lib -L$(DATAMAN_LOC)/lib -ldataman # -lcacheman -lstreamman -lzmqman
 
 #COMPILER FLAGS
 CFLAGS=-Wall -O0 -g -Wpedantic -std=c++11
diff --git a/include/engine/bp/BPWriter.h b/include/engine/bp/BPWriter.h
index ce99908c6..6e1c82267 100644
--- a/include/engine/bp/BPWriter.h
+++ b/include/engine/bp/BPWriter.h
@@ -74,6 +74,10 @@ public:
 
     void AdvanceStep( );
 
+    /**
+     * Closes a single transport or all transports
+     * @param transportIndex, if -1 (default) closes all transports, otherwise it closes a transport in m_Transport[transportIndex]. In debug mode the latter is bounds-checked.
+     */
     void Close( const int transportIndex = -1 );
 
 private:
@@ -81,7 +85,7 @@ private:
     capsule::STLVector m_Buffer; ///< heap capsule using STL std::vector<char>
     std::size_t m_BufferVariableCountPosition = 0; ///< needs to be updated in every advance step
     bool m_IsFirstClose = true; ///< set to false after first Close is reached so metadata doesn't have to be accommodated for a subsequent Close
-    std::size_t m_MaxBufferSize;
+    std::size_t m_MaxBufferSize; ///< maximum allowed memory to be allocated
     float m_GrowthFactor = 1.5; ///< capsule memory growth factor, new_memory = m_GrowthFactor * current_memory
 
     format::BP1Writer m_BP1Writer; ///< format object will provide the required BP functionality to be applied on m_Buffer and m_Transports
diff --git a/src/engine/bp/BPWriter.cpp b/src/engine/bp/BPWriter.cpp
index ad6c7de2f..ff3f65960 100644
--- a/src/engine/bp/BPWriter.cpp
+++ b/src/engine/bp/BPWriter.cpp
@@ -177,19 +177,6 @@ void BPWriter::Close( const int transportIndex )
     {
         m_BP1Writer.Close( m_MetadataSet, m_Buffer, *m_Transports[transportIndex], m_IsFirstClose );
     }
-
-    //BP1Writer to update the metadata indices
-
-
-
-    //merge all metadata indices in capsule.m_Metadata buffer or capsule.m_Data buffer (depends on transport predefined functionality)
-
-
-    //BP1BPWriter to write to corresponding transport
-
-
-
-    //Close the corresponding transport
 }
 
 
diff --git a/src/format/BP1Writer.cpp b/src/format/BP1Writer.cpp
index 59eb3a126..fbbd68c3d 100644
--- a/src/format/BP1Writer.cpp
+++ b/src/format/BP1Writer.cpp
@@ -253,7 +253,7 @@ void BP1Writer::FlattenMetadata( BP1MetadataSet& metadataSet, Capsule& capsule )
     const std::uint64_t offsetPGIndex = capsule.m_DataAbsolutePosition;
     const std::uint64_t offsetVarsIndex = offsetPGIndex + pgLength;
     const std::uint64_t offsetAttributeIndex = offsetVarsIndex + varsIndexLength;
-    std::size_t position = attributesIndexLength;
+    std::size_t position = pgLength + varsIndexLength + attributesIndexLength;
 
     //offsets
     std::memcpy( &metadata[position], &offsetPGIndex, 8 );
-- 
GitLab