Skip to content

Commit

Permalink
implement various fixes for warnings issued by MSVC, re #49
Browse files Browse the repository at this point in the history
  • Loading branch information
gentryx committed Mar 1, 2017
1 parent 5d661b7 commit b471002
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 53 deletions.
14 changes: 7 additions & 7 deletions src/examples/hardwarefluke/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class BuggyCell
{}

template<typename COORD_MAP>
void update(const COORD_MAP& neighbors, unsigned nanoStep)
void update(const COORD_MAP& neighbors, unsigned /* nanoStep */)
{
int buf = (neighbors[Coord<2>(0, -1)].val + neighbors[Coord<2>(-1, 0)].val +
neighbors[Coord<2>(1, 0)].val + neighbors[Coord<2>( 0, 1)].val);
val = (buf >> 2) + 1;
neighbors[Coord<2>(1, 0)].val + neighbors[Coord<2>( 0, 1)].val);
val = char((buf >> 2) + 1);
}

private:
Expand All @@ -34,7 +34,7 @@ class BuggyCell
class BuggyCellInitializer : public SimpleInitializer<BuggyCell>
{
public:
explicit BuggyCellInitializer(std::string infile, unsigned steps=10000) :
explicit BuggyCellInitializer(std::string infile, unsigned steps = 10000) :
SimpleInitializer<BuggyCell>(readDim(infile), steps),
filename(infile)
{}
Expand Down Expand Up @@ -88,9 +88,9 @@ class BuggyCellToColor
public:
Color operator[](char val) const
{
unsigned char r = ((val >> 5) & 7) * 255 / 7;
unsigned char g = ((val >> 2) & 7) * 255 / 7;
unsigned char b = ((val >> 0) & 3) * 255 / 3;
int r = ((val >> 5) & 7) * 255 / 7;
int g = ((val >> 2) & 7) * 255 / 7;
int b = ((val >> 0) & 3) * 255 / 3;
return Color(r, g, b);
}
};
Expand Down
29 changes: 20 additions & 9 deletions src/libgeodecomp/geometry/region.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ class ConstructStreakFromIterators<0>
}
};

// Hardwire this warning to off as MSVC would otherwise complain about
// an assignment operator missing -- which is clearly there:
#ifdef _MSC_BUILD
#pragma warning( push )
#pragma warning( disable : 4626 )
#endif

/**
* internal helper class
*/
Expand All @@ -165,6 +172,11 @@ class StreakIteratorInitPlaneOffset
offset(offset)
{}

#ifdef LIBGEODECOMP_WITH_CPP14
inline StreakIteratorInitPlaneOffset(const StreakIteratorInitPlaneOffset& other) = default;
inline StreakIteratorInitPlaneOffset(StreakIteratorInitPlaneOffset&& other) = default;
#endif

template<int STREAK_DIM, typename REGION>
inline void operator()(
Streak<STREAK_DIM> *streak,
Expand All @@ -173,9 +185,10 @@ class StreakIteratorInitPlaneOffset
const Coord<STREAK_DIM>& unusedOffsets,
int unusedAdditionalLength) const
{
iterators[DIM] = region.indicesBegin(DIM) + offset;
iterators[DIM] = region.indicesBegin(DIM) + std::ptrdiff_t(offset);
for (int d = DIM - 1; d >= 0; --d) {
iterators[d] = region.indicesBegin(d) + iterators[d + 1]->second;
std::size_t index = std::size_t(d);
iterators[index] = region.indicesBegin(index) + iterators[index + 1]->second;
}

ConstructStreakFromIterators<DIM>()(streak, iterators, unusedOffsets, unusedAdditionalLength);
Expand All @@ -199,6 +212,11 @@ class StreakIteratorInitSingleOffset
offsetIndex(offsetIndex)
{}

#ifdef LIBGEODECOMP_WITH_CPP14
inline StreakIteratorInitSingleOffset(const StreakIteratorInitSingleOffset& other) = default;
inline StreakIteratorInitSingleOffset(StreakIteratorInitSingleOffset&& other) = default;
#endif

template<int STREAK_DIM, typename REGION>
inline std::size_t operator()(
Streak<STREAK_DIM> *streak,
Expand All @@ -223,13 +241,6 @@ class StreakIteratorInitSingleOffset
const std::size_t offsetIndex;
};

// Hardwire this warning to off as MSVC would otherwise complain about
// an assignment operator missing -- which is clearly there:
#ifdef _MSC_BUILD
#pragma warning( push )
#pragma warning( disable : 4626 )
#endif

/**
* internal helper class
*/
Expand Down
2 changes: 1 addition & 1 deletion src/libgeodecomp/io/simplecellplotter.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CellToColor : public Filter<CELL, MEMBER, Color>
void copyStreakInImpl(
const Color* /* source */,
MemoryLocation::Location sourceLocation,
MEMBER *target,
MEMBER* /* target */,
MemoryLocation::Location targetLocation,
const std::size_t /* num */,
const std::size_t /* stride */)
Expand Down
2 changes: 1 addition & 1 deletion src/libgeodecomp/io/test/parallel_mpi_1/plottertest.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TestCellPalette
public:
Color operator[](const double value) const
{
return Color(value, 47, 11);
return Color(value, 47.0, 11.0);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/libgeodecomp/io/test/parallel_mpi_1/ppmwritertest.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TestCellPalette
public:
Color operator[](const double value) const
{
return Color(value, 47, 11);
return Color(value, 47.0, 11.0);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class MyQtCellColorConverter
public:
Color operator()(const MyQtTestCell& cell)
{
return Color(255, cell.temp * 255, 0);
return Color(255.0, cell.temp * 255, 0.0);
}
};

Expand Down
45 changes: 32 additions & 13 deletions src/libgeodecomp/misc/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,40 @@ class Color

unsigned rgb;

inline Color() { *this = Color(0, 0, 0); }
inline Color() :
rgb(255 << 24)
{}

inline Color(
const unsigned char& r,
const unsigned char& g,
const unsigned char& b)
{
rgb = 255;
rgb <<= 8;
rgb += r;
rgb <<= 8;
rgb += g;
rgb <<= 8;
rgb += b;
}
const unsigned char r,
const unsigned char g,
const unsigned char b) :
rgb((255 << 24) + (r << 16) + (g << 8) + b)
{}

inline Color(
const char r,
const char g,
const char b) :
rgb((255 << 24) +
(static_cast<unsigned char>(r) << 16) +
(static_cast<unsigned char>(g) << 8) +
static_cast<unsigned char>(b))
{}

inline Color(
const int r,
const int g,
const int b) :
rgb((255 << 24) + (r << 16) + (g << 8) + b)
{}

inline Color(
const double r,
const double g,
const double b) :
rgb((255 << 24) + (int(r) << 16) + (int(g) << 8) + int(b))
{}

unsigned char red() const
{
Expand Down
8 changes: 4 additions & 4 deletions src/libgeodecomp/misc/quickpalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ class QuickPalette
}

if (val < mark1) {
return Color(0, (val - mark0) * mult, 255);
return Color(0.0, (val - mark0) * mult, 255.0);
}

if (val < mark2) {
return Color(0, 255, (mark2 - val) * mult);
return Color(0.0, 255.0, (mark2 - val) * mult);
}

if (val < mark3) {
return Color((val - mark2) * mult, 255, 0);
return Color((val - mark2) * mult, 255.0, 0.0);
}

return Color(255, (mark4 - val) * mult, 0);
return Color(255.0, (mark4 - val) * mult, 0.0);
}

private:
Expand Down
4 changes: 2 additions & 2 deletions src/libgeodecomp/storage/test/unit/selectortest.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class SelectorTest : public CxxTest::TestSuite
const std::size_t stride)
{
for (std::size_t i = 0; i < num; ++i) {
target[i] = Color(source[i], 47, 11);
target[i] = Color(source[i], 47.0, 11.0);
}
}

Expand All @@ -199,7 +199,7 @@ class SelectorTest : public CxxTest::TestSuite
double MyDummyCell:: *memberPointer)
{
for (std::size_t i = 0; i < num; ++i) {
target[i] = Color(source[i].*memberPointer, 47, 11);
target[i] = Color(source[i].*memberPointer, 47.0, 11.0);
}
}
};
Expand Down
30 changes: 16 additions & 14 deletions src/libgeodecomp/storage/updatefunctormacrosmsvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
#define LIBGEODECOMP_STORAGE_UPDATEFUNCTORMACROSMSVC_H

// MSVC doesn't have a _Pragma(), but requires __pragma(), hence here
// is basically a copy of updatefunctormacros.h:
// is basically a copy of updatefunctormacros.h. Oh, but of course we
// have to shun all std::size_t loop counters as MSVC wouldn't accept
// it as loop counter for OpenMP.
#ifdef _MSC_BUILD

#ifdef LIBGEODECOMP_WITH_THREADS
#define LGD_UPDATE_FUNCTOR_THREADING_SELECTOR_1 \
if (concurrencySpec.enableOpenMP() && \
!modelThreadingSpec.hasOpenMP()) { \
if (concurrencySpec.preferStaticScheduling()) { \
__pragma("omp parallel for schedule(static)") \
for (std::size_t c = 0; c < region.numPlanes(); ++c) { \
__pragma(omp parallel for schedule(static)) \
for (int c = 0; c < int(region.numPlanes()); ++c) { \
typename Region<DIM>::StreakIterator e = \
region.planeStreakIterator(c + 1); \
region.planeStreakIterator(std::size_t(c + 1)); \
typedef typename Region<DIM>::StreakIterator Iter; \
for (Iter i = region.planeStreakIterator(c + 0); \
for (Iter i = region.planeStreakIterator(std::size_t(c + 0)); \
i != e; \
++i) { \
LGD_UPDATE_FUNCTOR_BODY; \
Expand All @@ -25,12 +27,12 @@
#define LGD_UPDATE_FUNCTOR_THREADING_SELECTOR_2 \
} else { \
if (!concurrencySpec.preferFineGrainedParallelism()) { \
__pragma("omp parallel for schedule(dynamic)") \
for (std::size_t c = 0; c < region.numPlanes(); ++c) { \
__pragma(omp parallel for schedule(dynamic)) \
for (int c = 0; c < int(region.numPlanes()); ++c) { \
typename Region<DIM>::StreakIterator e = \
region.planeStreakIterator(c + 1); \
region.planeStreakIterator(std::size_t(c + 1)); \
typedef typename Region<DIM>::StreakIterator Iter; \
for (Iter i = region.planeStreakIterator(c + 0); \
for (Iter i = region.planeStreakIterator(std::size_t(c + 0)); \
i != e; \
++i) { \
LGD_UPDATE_FUNCTOR_BODY; \
Expand All @@ -56,11 +58,11 @@
} \
streaks.push_back(s); \
} \
__pragma("omp parallel for schedule(dynamic)") \
for (std::size_t j = 0; j < streaks.size(); ++j) { \
Streak<DIM> *i = &streaks[j]; \
LGD_UPDATE_FUNCTOR_BODY; \
} \
__pragma(omp parallel for schedule(dynamic)) \
for (int j = 0; j < int(streaks.size()); ++j) { \
Streak<DIM> *i = &streaks[std::size_t(j)]; \
LGD_UPDATE_FUNCTOR_BODY; \
} \
} \
/**/
#define LGD_UPDATE_FUNCTOR_THREADING_SELECTOR_4 \
Expand Down

0 comments on commit b471002

Please sign in to comment.