Fixing compile error with std::swap

This commit is contained in:
Mark Berrill 2015-08-17 14:21:01 -04:00
parent 767f7d9d2b
commit f0ffbcb174
6 changed files with 34 additions and 13 deletions

View File

@ -441,7 +441,6 @@ int ComputeGlobalBlobIDs( int nx, int ny, int nz, const RankInfoStruct& rank_inf
IntArray& GlobalBlobID )
{
PROFILE_START("ComputeGlobalBlobIDs");
const int rank = rank_info.rank[1][1][1];
int nprocs;
MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
// First compute the local ids
@ -455,7 +454,6 @@ int ComputeGlobalPhaseComponent( int nx, int ny, int nz, const RankInfoStruct& r
const IntArray &PhaseID, int VALUE, IntArray &GlobalBlobID )
{
PROFILE_START("ComputeGlobalPhaseComponent");
const int rank = rank_info.rank[1][1][1];
int nprocs;
MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
// First compute the local ids

20
common/Array.cpp Normal file
View File

@ -0,0 +1,20 @@
#include "Array.h"
#include <stdint.h>
/********************************************************
* std::swap *
********************************************************/
namespace std
{
template<> void swap( Array<bool>& v1, Array<bool>& v2 ) { v1.swap(v2); }
template<> void swap( Array<char>& v1, Array<char>& v2 ) { v1.swap(v2); }
template<> void swap( Array<int>& v1, Array<int>& v2 ) { v1.swap(v2); }
template<> void swap( Array<unsigned int>& v1, Array<unsigned int>& v2 ) { v1.swap(v2); }
template<> void swap( Array<int64_t>& v1, Array<int64_t>& v2 ) { v1.swap(v2); }
template<> void swap( Array<uint64_t>& v1, Array<uint64_t>& v2 ) { v1.swap(v2); }
template<> void swap( Array<float>& v1, Array<float>& v2 ) { v1.swap(v2); }
template<> void swap( Array<double>& v1, Array<double>& v2 ) { v1.swap(v2); }
}

View File

@ -323,6 +323,8 @@ public:
//! Return the sum of all elements in a given direction
std::shared_ptr<Array<TYPE> > sum( int dir ) const;
//! Swap the data in this with rhs
inline void swap( Array& rhs );
private:
int d_ndim;

View File

@ -5,6 +5,7 @@
#include "common/Utilities.h"
#include <algorithm>
#include <limits>
#include <cstring>
template<class TYPE>
@ -313,17 +314,20 @@ void Array<TYPE>::fill( const TYPE& value )
d_data[i] = value;
}
/********************************************************
* std::swap *
* swap *
********************************************************/
template<class TYPE>
void std::swap(Array<TYPE>& v1, Array<TYPE>& v2)
inline void Array<TYPE>::swap( Array<TYPE>& rhs )
{
std::swap(v1.d_ndim,v2.d_ndim);
std::swap(v1.d_N,v2.d_N);
std::swap(v1.d_length,v2.d_length);
std::swap(v1.d_data,v2.d_data);
std::swap(v1.d_ptr,v2.d_ptr);
std::swap(d_ndim,rhs.d_ndim);
std::swap(d_length,rhs.d_length);
std::swap(d_data,rhs.d_data);
std::swap(d_ptr,rhs.d_ptr);
size_t N[4] = {d_N[0],d_N[1],d_N[2],d_N[3]};
memcpy(d_N,rhs.d_N,sizeof(d_N));
memcpy(rhs.d_N,N,sizeof(d_N));
}

View File

@ -814,7 +814,7 @@ int main(int argc, char **argv)
// Renumber the current timestep's ids
}
std::swap(GlobalBlobID,GlobalBlobID2);
GlobalBlobID.swap(GlobalBlobID2);
PROFILE_STOP("Identify blobs and maps");
}
if (timestep%1000 == 5){

View File

@ -42,9 +42,6 @@ int test_communication( MPI_Comm comm, int nprocx, int nprocy, int nprocz )
//**********************************
int Nx, Ny, Nz;
Nx = Ny = Nz = 10; // Cubic domain
// Set up MPI communication structurese
if (rank==0) printf ("Setting up communication control structures \n");
//......................................................................................