diff --git a/ippl/src/Message/CMakeLists.txt b/ippl/src/Message/CMakeLists.txt index cfa937fa8553b1351a1f4aabab432b46b5c84191..784123741c329bd2f0996c0a22f259f07d691caf 100644 --- a/ippl/src/Message/CMakeLists.txt +++ b/ippl/src/Message/CMakeLists.txt @@ -1,23 +1,25 @@ set (_SRCS CRC.cpp - Communicate.cpp CommCreator.cpp CommMPI.cpp + Communicate.cpp + Format.cpp MessageFunctions.cpp - Formatter.cpp + MsgBuffer.cpp ) set (_HDRS + CRC.h CommCreator.h CommMPI.h Communicate.h - CRC.h DataTypes.h - Formatter.h - GlobalComm.hpp + Format.h GlobalComm.h - Message.hpp + GlobalComm.hpp Message.h + Message.hpp + MsgBuffer.h Operations.h TagMaker.h Tags.h @@ -39,4 +41,4 @@ install (FILES ${_HDRS} DESTINATION include/Message) # cmake-tab-width: 4 # indent-tabs-mode: nil # require-final-newline: nil -# End: +# End: \ No newline at end of file diff --git a/ippl/src/Message/Format.cpp b/ippl/src/Message/Format.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bd76adb26887dca024b9eda52aa1e33082e9ce8e --- /dev/null +++ b/ippl/src/Message/Format.cpp @@ -0,0 +1,44 @@ +// +// Class Format +// Format class to allow serializing message objects into plain buffers +// to send directly with mpi calls or similar means +// +// Copyright (c) 2008 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland +// All rights reserved +// +// This file is part of OPAL. +// +// OPAL is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// You should have received a copy of the GNU General Public License +// along with OPAL. If not, see <https://www.gnu.org/licenses/>. +// +#include "Message/Format.h" + +Format::Format(Message *msg) +{ + items = msg->size(); + size = 0; + + format_array.resize(2*items); + for (unsigned int i=0; i<items; ++i) + { + Message::MsgItem &msgitem = msg->item(i); + format_array[2*i+0] = msgitem.numElems(); + format_array[2*i+1] = msgitem.numBytes(); + size += format_array[2*i+1]; + } +} + +void Format::print() +{ + std::cout << "size: " << size << std::endl; + for (unsigned int i=0; i<items; ++i) + { + std::cout << "entry " << i << ": " << format_array[2*i+0] + << " elements " << format_array[2*i+1] << " bytes\n"; + } +} \ No newline at end of file diff --git a/ippl/src/Message/Format.h b/ippl/src/Message/Format.h new file mode 100644 index 0000000000000000000000000000000000000000..5681662d0706b62f3f045c1ed3b0f0d53ecaf33f --- /dev/null +++ b/ippl/src/Message/Format.h @@ -0,0 +1,53 @@ +// +// Class Format +// Format class to allow serializing message objects into plain buffers +// to send directly with mpi calls or similar means +// +// Copyright (c) 2008 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland +// All rights reserved +// +// This file is part of OPAL. +// +// OPAL is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// You should have received a copy of the GNU General Public License +// along with OPAL. If not, see <https://www.gnu.org/licenses/>. +// +#ifndef FORMATTER_H +#define FORMATTER_H + +#include <algorithm> +#include <cstring> +#include <vector> +#include "Message/Message.h" + +class Format { +public: + Format(Message*); + unsigned int getItemCount() { + return items; + } + unsigned int getSize() { + return size; + } + unsigned int getFormatSize() { + return 2 * items * sizeof(int); + } + unsigned int getItemElems(int i) { + return format_array[2 * i + 0]; + } + unsigned int getItemBytes(int i) { + return format_array[2 * i + 1]; + } + + void print(); + +private: + unsigned int items, size; + std::vector<unsigned int> format_array; +}; + +#endif \ No newline at end of file diff --git a/ippl/src/Message/Formatter.h b/ippl/src/Message/Formatter.h deleted file mode 100644 index ce61ccd9f4c40b5cca30abb3fdbf057ba2c3309d..0000000000000000000000000000000000000000 --- a/ippl/src/Message/Formatter.h +++ /dev/null @@ -1,99 +0,0 @@ -// -*- C++ -*- -/*************************************************************************** - * - * The IPPL Framework - * - * - * Visit http://people.web.psi.ch/adelmann/ for more details - * - ***************************************************************************/ - -#ifndef FORMATTER_H -#define FORMATTER_H - -#include "Message/Message.h" -#include <cstring> -#include <vector> -#include <algorithm> - -/* - * Format and MsgBuffer class to allow serializing message objects into plain buffers - * to send directly with mpi calls or similar means - */ - -class Format -{ -public: - Format(Message*); - unsigned int getItemCount() - { - return items; - } - unsigned int getSize() - { - return size; - } - unsigned int getFormatSize() - { - return 2*items*sizeof(int); - } - unsigned int getItemElems(int i) - { - return format_array[2*i+0]; - } - unsigned int getItemBytes(int i) - { - return format_array[2*i+1]; - } - - void print(); - -private: - unsigned int items, size; - std::vector<unsigned int> format_array; -}; - - -class MsgBuffer -{ -public: - //creates buffer with space to hold count messages of format f - MsgBuffer(Format *f, int count, int offset = 0); - MsgBuffer(Format *f, char* d, int size); - - bool add(Message*); - Message* get(); - - template<class T> - void get(T &v) - { - std::memcpy(&v, data.data()+readpos, sizeof(T)); - readpos += sizeof(T); - } - - template<class T> - void put(T &v) - { - std::memcpy(data.data()+writepos, &v, sizeof(T)); - writepos += sizeof(T); - } - - int getSize() - { - return writepos; - } - void* getBuffer() - { - return data.data(); - } - - Format* getFormat() { return format; } - - ~MsgBuffer(); -private: - Format *format; - unsigned int datasize, writepos, readpos; - std::vector<char> data; -}; - -#endif // FORMATTER_H diff --git a/ippl/src/Message/Formatter.cpp b/ippl/src/Message/MsgBuffer.cpp similarity index 70% rename from ippl/src/Message/Formatter.cpp rename to ippl/src/Message/MsgBuffer.cpp index 2e21ab7652ac4476b111aff03385f2459595edb6..b3a6ed2b560c1acb9f623ab8bb678385d0b2e37b 100644 --- a/ippl/src/Message/Formatter.cpp +++ b/ippl/src/Message/MsgBuffer.cpp @@ -1,29 +1,24 @@ -#include "Message/Formatter.h" - -Format::Format(Message *msg) -{ - items = msg->size(); - size = 0; - - format_array.resize(2*items); - for (unsigned int i=0; i<items; ++i) - { - Message::MsgItem &msgitem = msg->item(i); - format_array[2*i+0] = msgitem.numElems(); - format_array[2*i+1] = msgitem.numBytes(); - size += format_array[2*i+1]; - } -} - -void Format::print() -{ - std::cout << "size: " << size << std::endl; - for (unsigned int i=0; i<items; ++i) - { - std::cout << "entry " << i << ": " << format_array[2*i+0] - << " elements " << format_array[2*i+1] << " bytes\n"; - } -} +// +// Class MsgBuffer +// MsgBuffer class to allow serializing message objects into plain buffers +// to send directly with mpi calls or similar means +// +// Copyright (c) 2008 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland +// All rights reserved +// +// This file is part of OPAL. +// +// OPAL is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// You should have received a copy of the GNU General Public License +// along with OPAL. If not, see <https://www.gnu.org/licenses/>. +// +#include "Message/MsgBuffer.h" + +#include "Message/Format.h" MsgBuffer::MsgBuffer(Format *f, int count, int offset) : format(f), writepos(0), readpos(0) @@ -94,4 +89,4 @@ Message* MsgBuffer::get() } return msg; -} +} \ No newline at end of file diff --git a/ippl/src/Message/MsgBuffer.h b/ippl/src/Message/MsgBuffer.h new file mode 100644 index 0000000000000000000000000000000000000000..3d2c29a9f43571080c30e3b69bc6af16c7ea6f9c --- /dev/null +++ b/ippl/src/Message/MsgBuffer.h @@ -0,0 +1,71 @@ +// +// Class MsgBuffer +// MsgBuffer class to allow serializing message objects into plain buffers +// to send directly with mpi calls or similar means +// +// Copyright (c) 2008 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland +// All rights reserved +// +// This file is part of OPAL. +// +// OPAL is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// You should have received a copy of the GNU General Public License +// along with OPAL. If not, see <https://www.gnu.org/licenses/>. +// +#ifndef MSGBUFFER_H +#define MSGBUFFER_H + +#include <algorithm> +#include <cstring> +#include <vector> +#include "Message/Message.h" + +class Format; + +class MsgBuffer { +public: + // creates buffer with space to hold count messages of format f + MsgBuffer(Format* f, int count, int offset = 0); + MsgBuffer(Format* f, char* d, int size); + + bool add(Message*); + Message* get(); + + template <class T> + void get(T& v) { + std::memcpy(&v, data.data() + readpos, sizeof(T)); + readpos += sizeof(T); + } + + template <class T> + void put(T& v) { + std::memcpy(data.data() + writepos, &v, sizeof(T)); + writepos += sizeof(T); + } + + int getSize() { + return writepos; + } + + void* getBuffer() { + char* data_ptr = data.empty() ? static_cast<char*>(0) : &(data[0]); + return data_ptr; + } + + Format* getFormat() { + return format; + } + + ~MsgBuffer(); + +private: + Format* format; + unsigned int datasize, writepos, readpos; + std::vector<char> data; +}; + +#endif \ No newline at end of file diff --git a/ippl/src/Particle/BoxParticleCachingPolicy.h b/ippl/src/Particle/BoxParticleCachingPolicy.h index 78884d0de83f05126b132685687332db3f8c78dc..ca5a8745cb6362010725fa8f4a9306851806c0cc 100644 --- a/ippl/src/Particle/BoxParticleCachingPolicy.h +++ b/ippl/src/Particle/BoxParticleCachingPolicy.h @@ -14,7 +14,8 @@ #include "Message/Message.h" #include "Message/Communicate.h" -#include "Message/Formatter.h" +#include "Message/Format.h" +#include "Message/MsgBuffer.h" template <class T, unsigned Dim, class Mesh, class CachingPolicy> class ParticleSpatialLayout; @@ -233,7 +234,8 @@ template<class C> } //wait for communication to finish and clean up buffers - MPI_Waitall(requests.size(), &(requests[0]), MPI_STATUSES_IGNORE); + MPI_Request* requests_ptr = requests.empty()? static_cast<MPI_Request*>(0): &(requests[0]); + MPI_Waitall(requests.size(), requests_ptr, MPI_STATUSES_IGNORE); for (unsigned int j = 0; j<buffers.size(); ++j) { delete buffers[j]->getFormat(); @@ -259,4 +261,4 @@ private: std::map<unsigned, std::list<std::pair<NDRegion<T,Dim>, Offset_t> > > regions; }; -#endif \ No newline at end of file +#endif diff --git a/ippl/src/Particle/IpplParticleBase.h b/ippl/src/Particle/IpplParticleBase.h index fa5e4a1639b8e8fdf6f6f90a6d45f2c475795ebe..b38aef195506839fc4080392f62204ef9bb17bb4 100644 --- a/ippl/src/Particle/IpplParticleBase.h +++ b/ippl/src/Particle/IpplParticleBase.h @@ -98,7 +98,8 @@ #include "AppTypes/Vektor.h" #include "DataSource/DataSource.h" #include "DataSource/MakeDataSource.h" -#include "Message/Formatter.h" +#include "Message/Format.h" +#include "Message/MsgBuffer.h" #include <vector> #include <algorithm> // Include algorithms #include <utility> @@ -398,4 +399,4 @@ private: * $RCSfile: IpplParticleBase.h,v $ $Author: adelmann $ * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:28 $ * IPPL_VERSION_ID: $Id: IpplParticleBase.h,v 1.1.1.1 2003/01/23 07:40:28 adelmann Exp $ - ***************************************************************************/ \ No newline at end of file + ***************************************************************************/ diff --git a/ippl/src/Particle/ParticleSpatialLayout.h b/ippl/src/Particle/ParticleSpatialLayout.h index edd0b63c525c4b6e44543848dcd0c5c482f6c422..cc392eee5fa39d541eabff6a932aa67c62b27013 100644 --- a/ippl/src/Particle/ParticleSpatialLayout.h +++ b/ippl/src/Particle/ParticleSpatialLayout.h @@ -26,6 +26,8 @@ #include "Particle/IpplParticleBase.h" #include "Region/RegionLayout.h" #include "Message/Message.h" +#include "Message/Format.h" +#include "Message/MsgBuffer.h" #include "FieldLayout/FieldLayoutUser.h" #include "Utility/IpplException.h" @@ -39,7 +41,6 @@ #include "BoxParticleCachingPolicy.h" -#include "Message/Formatter.h" #include <mpi.h> // forward declarations @@ -1197,7 +1198,8 @@ protected: } //wait for communication to finish and clean up buffers - MPI_Waitall(requests.size(), &(requests[0]), MPI_STATUSES_IGNORE); + MPI_Request* requests_ptr = requests.empty()? static_cast<MPI_Request*>(0): &(requests[0]); + MPI_Waitall(requests.size(), requests_ptr, MPI_STATUSES_IGNORE); return LocalNum; } @@ -1326,7 +1328,8 @@ protected: } //wait for communication to finish and clean up buffers - MPI_Waitall(requests.size(), &(requests[0]), 0); + MPI_Request* requests_ptr = requests.empty()? static_cast<MPI_Request*>(0): &(requests[0]); + MPI_Waitall(requests.size(), requests_ptr, 0); return LocalNum; } diff --git a/src/Amr/BoxLibLayout.hpp b/src/Amr/BoxLibLayout.hpp index c898753d4f07a595418b9644f66103a487dcaeca..4ad6635909653b2dc60ab02320544c1b68f21f6a 100644 --- a/src/Amr/BoxLibLayout.hpp +++ b/src/Amr/BoxLibLayout.hpp @@ -38,7 +38,9 @@ #include "BoxLibLayout.h" -#include "Message/Formatter.h" +#include "Message/Format.h" +#include "Message/MsgBuffer.h" +#include "Utility/PAssert.h" #include "Utilities/OpalException.h" #include <cassert> @@ -348,7 +350,8 @@ void BoxLibLayout<T, Dim>::update(AmrParticleBase< BoxLibLayout<T,Dim> >& PData, } //wait for communication to finish and clean up buffers - MPI_Waitall(requests.size(), &(requests[0]), MPI_STATUSES_IGNORE); + MPI_Request* requests_ptr = requests.empty()? static_cast<MPI_Request*>(0): &(requests[0]); + MPI_Waitall(requests.size(), requests_ptr, MPI_STATUSES_IGNORE); for (unsigned int j = 0; j<buffers.size(); ++j) { delete buffers[j]; @@ -479,7 +482,7 @@ void BoxLibLayout<T, Dim>::clearLevelMask(int lev) { template <class T, unsigned Dim> -const std::unique_ptr<typename BoxLibLayout<T, Dim>::mask_t>& +const std::unique_ptr<typename BoxLibLayout<T, Dim>::mask_t>& BoxLibLayout<T, Dim>::getLevelMask(int lev) const { if ( lev >= (int)masks_m.size() ) { throw OpalException("BoxLibLayout::getLevelMask()", diff --git a/src/Classic/Structure/LossDataSink.cpp b/src/Classic/Structure/LossDataSink.cpp index 866a39b3f62bb7a7a416c1bf6c8a21f3ada5f123..2096fec53719436d9b69e692def25986092d8d1c 100644 --- a/src/Classic/Structure/LossDataSink.cpp +++ b/src/Classic/Structure/LossDataSink.cpp @@ -368,22 +368,22 @@ void LossDataSink::saveH5(unsigned int setIdx) { WRITE_STEPATTRIB_INT64("GlobalTrackStep", &(globalTrackStep_m[setIdx]), 1); } // Write all data - WRITE_DATA_FLOAT64 ("x", &x_m[startIdx]); - WRITE_DATA_FLOAT64 ("y", &y_m[startIdx]); - WRITE_DATA_FLOAT64 ("z", &z_m[startIdx]); - WRITE_DATA_FLOAT64 ("px", &px_m[startIdx]); - WRITE_DATA_FLOAT64 ("py", &py_m[startIdx]); - WRITE_DATA_FLOAT64 ("pz", &pz_m[startIdx]); + WRITE_DATA_FLOAT64 ("x", x_m.data() + startIdx); + WRITE_DATA_FLOAT64 ("y", y_m.data() + startIdx); + WRITE_DATA_FLOAT64 ("z", z_m.data() + startIdx); + WRITE_DATA_FLOAT64 ("px", px_m.data() + startIdx); + WRITE_DATA_FLOAT64 ("py", py_m.data() + startIdx); + WRITE_DATA_FLOAT64 ("pz", pz_m.data() + startIdx); /// Write particle id numbers. std::vector<h5_int64_t> larray(id_m.begin() + startIdx, id_m.end() ); - WRITE_DATA_INT64 ("id", &larray[0]); + WRITE_DATA_INT64 ("id", larray.data()); if (hasTimeAttribute()) { - WRITE_DATA_FLOAT64 ("time", &time_m[startIdx]); + WRITE_DATA_FLOAT64 ("time", time_m.data() + startIdx); larray.assign (turn_m.begin() + startIdx, turn_m.end() ); - WRITE_DATA_INT64 ("turn", &larray[0]); + WRITE_DATA_INT64 ("turn", larray.data()); larray.assign (bunchNum_m.begin() + startIdx, bunchNum_m.end() ); - WRITE_DATA_INT64 ("bunchNumber", &larray[0]); + WRITE_DATA_INT64 ("bunchNumber", larray.data()); } ++ H5call_m; @@ -688,4 +688,4 @@ SetStatistics LossDataSink::computeSetStatistics(unsigned int setIdx) { // c-basic-offset: 4 // indent-tabs-mode: nil // require-final-newline: nil -// End: +// End: \ No newline at end of file diff --git a/src/Classic/Utilities/Util.h b/src/Classic/Utilities/Util.h index 44816c5a14fb74d097b343aeeea91d2952c61930..96a6ca110ed81b997f40ff1b6b02fdcf1225eca2 100644 --- a/src/Classic/Utilities/Util.h +++ b/src/Classic/Utilities/Util.h @@ -196,6 +196,13 @@ namespace Util { std::string base64_encode(const std::string &string_to_encode);//unsigned char const* , unsigned int len); std::string base64_decode(std::string const& s); + + template<typename T, typename A> + T* c_data(std::vector<T,A>& v) { return v.empty() ? static_cast<T*>(0) : &(v[0]); } + + template<typename T, typename A> + T const* c_data(std::vector<T,A> const& v) { return v.empty() ? static_cast<T const*>(0) : &(v[0]); } + } template <typename T> diff --git a/src/Distribution/Distribution.cpp b/src/Distribution/Distribution.cpp index 1cf37f4dbaa88696e7dc0fab1833f8c3b3679aa7..629dbe02777f63fe3c9de722e20fb6e4e5b0a157 100644 --- a/src/Distribution/Distribution.cpp +++ b/src/Distribution/Distribution.cpp @@ -1003,11 +1003,13 @@ size_t Distribution::getNumberOfParticlesInFile(std::ifstream &inputFile) { void Distribution::createDistributionFromFile(size_t /*numberOfParticles*/, double massIneV) { *gmsg << level3 << "\n" - << "------------------------------------------------------------------------------------\n"; + << "-------------------------------------------------------------------" + "-----------------\n"; *gmsg << "READ INITIAL DISTRIBUTION FROM FILE \"" - << Attributes::getString(itsAttr[Attrib::Distribution::FNAME]) - << "\"\n"; - *gmsg << "------------------------------------------------------------------------------------\n" << endl; + << Attributes::getString(itsAttr[Attrib::Distribution::FNAME]) << "\"\n"; + *gmsg << "-------------------------------------------------------------------" + "-----------------\n" + << endl; // Data input file is only read by node 0. std::ifstream inputFile; @@ -1030,26 +1032,25 @@ void Distribution::createDistributionFromFile(size_t /*numberOfParticles*/, doub pmean_m = 0.0; - size_t numPartsToSend = 0; unsigned int distributeFrequency = 1000; - size_t singleDataSize = (/*sizeof(int) +*/ 6 * sizeof(double)); - unsigned int dataSize = distributeFrequency * singleDataSize; - std::vector<char> data; + size_t singleDataSize = 6; + unsigned int dataSize = distributeFrequency * singleDataSize; + std::vector<double> data(dataSize); - data.reserve(dataSize); - - const char* buffer; if (Ippl::myNode() == 0) { - char lineBuffer[1024]; - unsigned int numParts = 0; + constexpr unsigned int bufferSize = 1024; + char lineBuffer[bufferSize]; + unsigned int numParts = 0; + std::vector<double>::iterator currentPosition = data.begin(); while (!inputFile.eof()) { - inputFile.getline(lineBuffer, 1024); + inputFile.getline(lineBuffer, bufferSize); Vector_t R(0.0), P(0.0); std::istringstream line(lineBuffer); line >> R(0); - if (line.rdstate()) break; + if (line.rdstate()) + break; line >> P(0); line >> R(1); line >> P(1); @@ -1068,19 +1069,14 @@ void Distribution::createDistributionFromFile(size_t /*numberOfParticles*/, doub pmean_m += P; if (saveProcessor > 0u) { - buffer = reinterpret_cast<const char*>(&R[0]); - data.insert(data.end(), buffer, buffer + 3 * sizeof(double)); - buffer = reinterpret_cast<const char*>(&P[0]); - data.insert(data.end(), buffer, buffer + 3 * sizeof(double)); - ++ numPartsToSend; + currentPosition = std::copy(&(R[0]), &(R[0]) + 3, currentPosition); + currentPosition = std::copy(&(P[0]), &(P[0]) + 3, currentPosition); - if (numPartsToSend % distributeFrequency == 0) { + if (currentPosition == data.end()) { MPI_Bcast(&dataSize, 1, MPI_UNSIGNED, 0, Ippl::getComm()); - MPI_Bcast(&data[0], dataSize, MPI_CHAR, 0, Ippl::getComm()); - numPartsToSend = 0; + MPI_Bcast(&(data[0]), dataSize, MPI_DOUBLE, 0, Ippl::getComm()); - std::vector<char>().swap(data); - data.reserve(dataSize); + currentPosition = data.begin(); } } else { xDist_m.push_back(R(0)); @@ -1091,53 +1087,49 @@ void Distribution::createDistributionFromFile(size_t /*numberOfParticles*/, doub pzDist_m.push_back(P(2)); } - ++ numParts; - ++ saveProcessor; + ++numParts; + ++saveProcessor; } - dataSize = (numberOfParticlesRead == numParts? data.size(): std::numeric_limits<unsigned int>::max()); + dataSize = + (numberOfParticlesRead == numParts ? currentPosition - data.begin() + : std::numeric_limits<unsigned int>::max()); + MPI_Bcast(&dataSize, 1, MPI_UNSIGNED, 0, Ippl::getComm()); if (numberOfParticlesRead != numParts) { - throw OpalException("Distribution::createDistributionFromFile", - "Found " + - std::to_string(numParts) + - " particles in file '" + - fileName + - "' instead of " + - std::to_string(numberOfParticlesRead)); + throw OpalException( + "Distribution::createDistributionFromFile", + "Found " + std::to_string(numParts) + " particles in file '" + fileName + + "' instead of " + std::to_string(numberOfParticlesRead)); } - MPI_Bcast(&data[0], dataSize, MPI_CHAR, 0, Ippl::getComm()); + MPI_Bcast(&(data[0]), dataSize, MPI_DOUBLE, 0, Ippl::getComm()); } else { do { MPI_Bcast(&dataSize, 1, MPI_UNSIGNED, 0, Ippl::getComm()); if (dataSize == std::numeric_limits<unsigned int>::max()) { - throw OpalException("Distribution::createDistributionFromFile", - "Couldn't find " + - std::to_string(numberOfParticlesRead) + - " particles in file '" + - fileName + "'"); + throw OpalException( + "Distribution::createDistributionFromFile", + "Couldn't find " + std::to_string(numberOfParticlesRead) + + " particles in file '" + fileName + "'"); } - MPI_Bcast(&data[0], dataSize, MPI_CHAR, 0, Ippl::getComm()); + MPI_Bcast(&(data[0]), dataSize, MPI_DOUBLE, 0, Ippl::getComm()); size_t i = 0; while (i < dataSize) { - - if (saveProcessor + 1 == (unsigned) Ippl::myNode()) { - const double *tmp = reinterpret_cast<const double*>(&data[i]); + if (saveProcessor + 1 == (unsigned)Ippl::myNode()) { + const double* tmp = &(data[i]); xDist_m.push_back(tmp[0]); yDist_m.push_back(tmp[1]); tOrZDist_m.push_back(tmp[2]); pxDist_m.push_back(tmp[3]); pyDist_m.push_back(tmp[4]); pzDist_m.push_back(tmp[5]); - i += 6 * sizeof(double); - } else { - i += singleDataSize; } + i += singleDataSize; - ++ saveProcessor; - if (saveProcessor + 1 >= (unsigned) Ippl::getNodes()) { + ++saveProcessor; + if (saveProcessor + 1 >= (unsigned)Ippl::getNodes()) { saveProcessor = 0; } } @@ -1151,7 +1143,6 @@ void Distribution::createDistributionFromFile(size_t /*numberOfParticles*/, doub inputFile.close(); } - void Distribution::createMatchedGaussDistribution(size_t numberOfParticles, double massIneV, double charge) @@ -4462,4 +4453,4 @@ void Distribution::adjustPhaseSpace(double massIneV) { // c-basic-offset: 4 // indent-tabs-mode: nil // require-final-newline: nil -// End: +// End: \ No newline at end of file diff --git a/src/Structure/H5PartWrapper.cpp b/src/Structure/H5PartWrapper.cpp index 109ef19225d6963ed66a089614a8b338f0c06435..f16d32a0e076a6f6ad7b33bbcc9441287e9c5cd0 100644 --- a/src/Structure/H5PartWrapper.cpp +++ b/src/Structure/H5PartWrapper.cpp @@ -459,10 +459,11 @@ void H5PartWrapper::copyStepData( REPORTONERROR(H5PartSetNumParticles(file_m, numParticles)); std::vector<char> buffer(numParticles * sizeof(h5_float64_t)); - h5_float32_t *f32buffer = reinterpret_cast<h5_float32_t*>(&buffer[0]); - h5_float64_t *f64buffer = reinterpret_cast<h5_float64_t*>(&buffer[0]); - h5_int32_t *i32buffer = reinterpret_cast<h5_int32_t*>(&buffer[0]); - h5_int64_t *i64buffer = reinterpret_cast<h5_int64_t*>(&buffer[0]); + char* buffer_ptr = Util::c_data(buffer); + h5_float32_t *f32buffer = reinterpret_cast<h5_float32_t*>(buffer_ptr); + h5_float64_t *f64buffer = reinterpret_cast<h5_float64_t*>(buffer_ptr); + h5_int32_t *i32buffer = reinterpret_cast<h5_int32_t*>(buffer_ptr); + h5_int64_t *i64buffer = reinterpret_cast<h5_int64_t*>(buffer_ptr); h5_ssize_t numDatasets = H5PartGetNumDatasets(source); @@ -533,4 +534,4 @@ size_t H5PartWrapper::getNumParticles() const { // c-basic-offset: 4 // indent-tabs-mode: nil // require-final-newline: nil -// End: +// End: \ No newline at end of file diff --git a/src/Structure/H5PartWrapperForPC.cpp b/src/Structure/H5PartWrapperForPC.cpp index 09fc259388965d6faed06d8822852a14dee4b1d0..3229b4857a2eb1c7f4b5fbe69cf3bc657fdca78b 100644 --- a/src/Structure/H5PartWrapperForPC.cpp +++ b/src/Structure/H5PartWrapperForPC.cpp @@ -163,7 +163,9 @@ void H5PartWrapperForPC::readStepData(PartBunchBase<double, 3>* bunch, numParticles = lastParticle - firstParticle + 1; std::vector<char> buffer(numParticles * sizeof(h5_float64_t)); - h5_float64_t *f64buffer = reinterpret_cast<h5_float64_t*>(&buffer[0]); + char* buffer_ptr = Util::c_data(buffer); + h5_float64_t *f64buffer = reinterpret_cast<h5_float64_t*>(buffer_ptr); + h5_int64_t *i64buffer = reinterpret_cast<h5_int64_t*>(buffer_ptr); READDATA(Float64, file_m, "x", f64buffer); for(long int n = 0; n < numParticles; ++ n) { @@ -207,16 +209,12 @@ void H5PartWrapperForPC::readStepData(PartBunchBase<double, 3>* bunch, } if ( bunch->getNumBunch() > 1 ) { - std::vector<char> ibuffer(numParticles * sizeof(h5_int64_t)); - h5_int64_t *i64buffer = reinterpret_cast<h5_int64_t*>(&ibuffer[0]); READDATA(Int64, file_m, "bin", i64buffer); for(long int n = 0; n < numParticles; ++ n) { bunch->Bin[n] = i64buffer[n]; } } - std::vector<char> ibuffer(numParticles * sizeof(h5_int64_t)); - h5_int64_t *i64buffer = reinterpret_cast<h5_int64_t*>(&ibuffer[0]); READDATA(Int64, file_m, "bunchNumber", i64buffer); for(long int n = 0; n < numParticles; ++ n) { bunch->bunchNum[n] = i64buffer[n]; @@ -488,8 +486,9 @@ void H5PartWrapperForPC::writeStepData(PartBunchBase<double, 3>* bunch) { const size_t skipID = IDZero; std::vector<char> buffer(numLocalParticles * sizeof(h5_float64_t)); - h5_float64_t *f64buffer = reinterpret_cast<h5_float64_t*>(&buffer[0]); - h5_int64_t *i64buffer = reinterpret_cast<h5_int64_t*> (&buffer[0]); + char* buffer_ptr = Util::c_data(buffer); + h5_float64_t *f64buffer = reinterpret_cast<h5_float64_t*>(buffer_ptr); + h5_int64_t *i64buffer = reinterpret_cast<h5_int64_t*> (buffer_ptr); REPORTONERROR(H5PartSetNumParticles(file_m, numLocalParticles)); diff --git a/src/Structure/H5PartWrapperForPT.cpp b/src/Structure/H5PartWrapperForPT.cpp index 8fe3529b4308a97f2fd90ae006f1aac7c8dc3dfe..da36c82fa1440bbcd43e47c832365b1fff79b6d1 100644 --- a/src/Structure/H5PartWrapperForPT.cpp +++ b/src/Structure/H5PartWrapperForPT.cpp @@ -141,8 +141,9 @@ void H5PartWrapperForPT::readStepData(PartBunchBase<double, 3>* bunch, h5_ssize_ numParticles = lastParticle - firstParticle + 1; std::vector<char> buffer(numParticles * sizeof(h5_float64_t)); - h5_float64_t *f64buffer = reinterpret_cast<h5_float64_t*>(&buffer[0]); - h5_int32_t *i32buffer = reinterpret_cast<h5_int32_t*>(&buffer[0]); + char* buffer_ptr = Util::c_data(buffer); + h5_float64_t *f64buffer = reinterpret_cast<h5_float64_t*>(buffer_ptr); + h5_int32_t *i32buffer = reinterpret_cast<h5_int32_t*>(buffer_ptr); READDATA(Float64, file_m, "x", f64buffer); for(long int n = 0; n < numParticles; ++ n) { @@ -389,9 +390,10 @@ void H5PartWrapperForPT::writeStepData(PartBunchBase<double, 3>* bunch) { REPORTONERROR(H5PartSetNumParticles(file_m, numLocalParticles)); std::vector<char> buffer(numLocalParticles * sizeof(h5_float64_t)); - h5_float64_t *f64buffer = reinterpret_cast<h5_float64_t*>(&buffer[0]); - h5_int64_t *i64buffer = reinterpret_cast<h5_int64_t*>(&buffer[0]); - h5_int32_t *i32buffer = reinterpret_cast<h5_int32_t*>(&buffer[0]); + char* buffer_ptr = Util::c_data(buffer); + h5_float64_t *f64buffer = reinterpret_cast<h5_float64_t*>(buffer_ptr); + h5_int64_t *i64buffer = reinterpret_cast<h5_int64_t*>(buffer_ptr); + h5_int32_t *i32buffer = reinterpret_cast<h5_int32_t*>(buffer_ptr); for(size_t i = 0; i < numLocalParticles; ++ i) f64buffer[i] = bunch->R[i](0); @@ -498,4 +500,4 @@ void H5PartWrapperForPT::writeStepData(PartBunchBase<double, 3>* bunch) { reportOnError(herr, __FILE__, __LINE__); } -} +} \ No newline at end of file