Navigation Menu

Skip to content

Commit

Permalink
This is a major commit. The code now compiles both with Visual Studio…
Browse files Browse the repository at this point in the history
… 2008 and gcc (albeit version 4.0.1 only) without any warnings, i.e. with /W4 /Wp64 for VS2008 and -Wall -Wextra for gcc.
  • Loading branch information
Jeffrey Vitter committed Dec 29, 2008
1 parent 3cbad09 commit e3d0845
Show file tree
Hide file tree
Showing 42 changed files with 409 additions and 290 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -14,7 +14,7 @@ if(WIN32)
#Get rid of safety warnings about fopen_s and friends
add_definitions("-D_CRT_SECURE_NO_WARNINGS")
else(WIN32)
add_definitions("-Wall")
add_definitions("-Wall -Wextra")
endif(WIN32)

check_include_files("unistd.h" TPIE_HAVE_UNISTD_H)
Expand Down
2 changes: 1 addition & 1 deletion apps/matrix/matrix_fill.h
Expand Up @@ -64,7 +64,7 @@ namespace tpie {
ami::err operate(T *out, ami::SCAN_FLAG *sf) {
if ((*sf = (cur_row < r))) {
*out = pemf->element(cur_row,cur_col);
if (!(cur_col = (cur_col+1) % c)) {
if ((cur_col = (cur_col+1) % c)==0) {
cur_row++;
}
return ami::SCAN_CONTINUE;
Expand Down
16 changes: 15 additions & 1 deletion apps/matrix/mm_colref.h
Expand Up @@ -33,7 +33,9 @@ namespace tpie {

T &operator[](const TPIE_OS_SIZE_T col) const;

friend class mm_matrix_base<T>;
mm_colref<T> &operator=(const mm_colref<T> &rhs);

friend class mm_matrix_base<T>;
friend class mm_matrix<T>;
};

Expand All @@ -53,6 +55,18 @@ namespace tpie {
T &mm_colref<T>::operator[](const TPIE_OS_SIZE_T row) const {
return m.elt(row,c);
}

template<class T>
mm_colref<T> &mm_colref<T>::operator=(const mm_colref<T> &rhs) {

if (c != rhs.c ) {
tp_assert(0, "Range error.");
}

m = rhs.m;

return *this;
}

} // namespace apps

Expand Down
17 changes: 16 additions & 1 deletion apps/matrix/mm_rowref.h
Expand Up @@ -31,6 +31,8 @@ namespace tpie {

T &operator[](const TPIE_OS_SIZE_T col) const;

mm_rowref<T> &operator=(const mm_rowref<T> &rhs);

friend class mm_matrix_base<T>;
friend class mm_matrix<T>;
};
Expand All @@ -50,7 +52,20 @@ namespace tpie {
T &mm_rowref<T>::operator[](const TPIE_OS_SIZE_T col) const {
return m.elt(r,col);
}


template<class T>
mm_rowref<T> &mm_rowref<T>::operator=(const mm_rowref<T> &rhs) {

if (r != rhs.r ) {
tp_assert(0, "Range error.");
}

m = rhs.m;

return *this;
}


} // namespace apps

} // namespace ami
Expand Down
44 changes: 12 additions & 32 deletions apps/matrix/parse_args.cpp
Expand Up @@ -16,35 +16,6 @@

using namespace tpie;

static TPIE_OS_OFFSET parse_number(char *s) {
TPIE_OS_OFFSET n;
TPIE_OS_OFFSET mult = 1;
size_t len = strlen(s);
if(isalpha(s[len-1])) {
switch(s[len-1]) {
case 'G':
case 'g':
mult = 1 << 30;
break;
case 'M':
case 'm':
mult = 1 << 20;
break;
case 'K':
case 'k':
mult = 1 << 10;
break;
default:
std::cerr << "Error parsing arguments: bad number format: " << s << "\n";
exit(-1);
break;
}
s[len-1] = '\0';
}
n = TPIE_OS_OFFSET(atof(s) * mult);
return n;
}

void parse_args(int argc, char **argv, struct options *application_opts,
void (*parse_app_opts)(int idx, char *opt_arg), bool stop_if_no_args) {
bool do_exit = false;
Expand Down Expand Up @@ -94,17 +65,26 @@ void parse_args(int argc, char **argv, struct options *application_opts,
switch (idx) {
case 1:
// mm_size should be small.
mm_sz = std::max(size_t(128*1024), static_cast<TPIE_OS_SIZE_T>(parse_number(opt_arg)));
mm_sz = std::max((TPIE_OS_SIZE_T)(128*1024), parse_number<TPIE_OS_SIZE_T>(opt_arg));
break;
case 2:
verbose = true;
TP_LOG_APP_DEBUG_ID("Setting verbose flag.");
break;
case 3:
test_size = parse_number(opt_arg);
test_size = parse_number<TPIE_OS_OFFSET>(opt_arg);
break;
case 4:
rnd_seed = std::max(1u, static_cast<unsigned int>(parse_number(opt_arg)));
#ifdef _WIN32
// Suppress warning 4267 (size mismatch of size_t and unsigned int) once.
// This is recommended by Visual Studio's dynamic help for warning C4267.
#pragma warning(disable : 4267)
#endif
rnd_seed = std::max<unsigned int>(1, parse_number<unsigned int>(opt_arg));
#ifdef _WIN32
// Reset to the default state.
#pragma warning(default : 4267)
#endif
break;
default:
parse_app_opts(idx, opt_arg);
Expand Down
29 changes: 29 additions & 0 deletions apps/matrix/parse_args.h
Expand Up @@ -12,6 +12,35 @@
#include <tpie/portability.h>
#include "getopts.h"

template <typename T>
T parse_number(char *s) {
T n;
T mult = 1;
size_t len = strlen(s);
if(isalpha(s[len-1])) {
switch(s[len-1]) {
case 'G':
case 'g':
mult = 1 << 30;
break;
case 'M':
case 'm':
mult = 1 << 20;
break;
case 'K':
case 'k':
mult = 1 << 10;
break;
default:
std::cerr << "Error parsing arguments: bad number format: " << s << "\n";
exit(-1);
break;
}
s[len-1] = '\0';
}
n = (T)(atof(s) * mult);
return n;
}

// Parse arguments for flags common to all test apps, as well as those
// specific to this particular app. aso points to a string of app
Expand Down
16 changes: 8 additions & 8 deletions apps/matrix/test_matrix_pad.cpp
Expand Up @@ -75,7 +75,7 @@ int main(int argc, char **argv) {
parse_args(argc, argv, app_opts, parse_app_opts);

if (verbose) {
std::cout << "test_size = " << test_size << "." << std::endl;
std::cout << "test_size = " << (int)test_size << "." << std::endl;
std::cout << "test_mm_size = " << static_cast<TPIE_OS_OUTPUT_SIZE_T>(test_mm_size) << "." << std::endl;
std::cout << "random_seed = " << random_seed << "." << std::endl;
} else {
Expand All @@ -85,7 +85,7 @@ int main(int argc, char **argv) {
// Set the amount of main memory:
MM_manager.set_memory_limit (test_mm_size);

apps::matrix<TPIE_OS_OFFSET> em0(test_size, test_size);
apps::matrix<TPIE_OS_OFFSET> em0((int)test_size, (int)test_size);

// Streams for reporting values to ascii streams.

Expand Down Expand Up @@ -131,17 +131,17 @@ int main(int argc, char **argv) {
{
// Pad the matrix.

apps::matrix_pad<int> smp(test_size, test_size, 7);
apps::matrix_pad<TPIE_OS_OFFSET> smp(test_size, test_size, 7);

apps::matrix<int> em1(7 * ((em0.rows() - 1)/7 + 1),
apps::matrix<TPIE_OS_OFFSET> em1(7 * ((em0.rows() - 1)/7 + 1),
7 * ((em0.cols() - 1)/7 + 1));

ae = ami::scan(&em0, &smp, &em1);


// Block permute the matrix.

apps::matrix<int> em1p(7 * ((em0.rows() - 1)/7 + 1),
apps::matrix<TPIE_OS_OFFSET> em1p(7 * ((em0.rows() - 1)/7 + 1),
7 * ((em0.cols() - 1)/7 + 1));

apps::perm_matrix_into_blocks pmib1(7 * ((em0.rows() - 1)/7 + 1),
Expand All @@ -156,7 +156,7 @@ int main(int argc, char **argv) {

// Un block permute it.

apps::matrix<int> em2(7 * ((em0.rows() - 1)/7 + 1),
apps::matrix<TPIE_OS_OFFSET> em2(7 * ((em0.rows() - 1)/7 + 1),
7 * ((em0.cols() - 1)/7 + 1));

apps::perm_matrix_outof_blocks pmob1(7 * ((em0.rows() - 1)/7 + 1),
Expand All @@ -167,9 +167,9 @@ int main(int argc, char **argv) {

// Unpad the matrix.

apps::matrix_unpad<int> smup(test_size, test_size, 7);
apps::matrix_unpad<TPIE_OS_OFFSET> smup(test_size, test_size, 7);

apps::matrix<int> em3(em0.rows(), em0.cols());
apps::matrix<TPIE_OS_OFFSET> em3(em0.rows(), em0.cols());

ae = ami::scan(&em2, &smup, &em3);

Expand Down
8 changes: 4 additions & 4 deletions apps/matrix/test_sparse_matrix.cpp
Expand Up @@ -131,14 +131,14 @@ int main(int argc, char **argv)

// Streams for reporting values to ascii streams.

std::ofstream *osc;
std::ofstream *osi;
std::ofstream *osf;
std::ofstream *osc = NULL;
std::ofstream *osi = NULL;
std::ofstream *osf = NULL;
ami::cxx_ostream_scan< apps::sm_elem<double> > *rptc = NULL;
ami::cxx_ostream_scan< apps::sm_elem<double> > *rpti = NULL;
ami::cxx_ostream_scan<double> *rptf = NULL;

std::istream *isb;
std::istream *isb = NULL;
ami::cxx_istream_scan<apps::sm_elem<double> > *readb = NULL;

if (report_results_count) {
Expand Down
4 changes: 2 additions & 2 deletions apps/rtree/bulkloader.h
Expand Up @@ -67,7 +67,7 @@ class scan_computeBoundingBox : public scan_object {
};

err operate(const rectangle<coord_t, bid_t>& in, SCAN_FLAG* sfin,
pair<rectangle<coord_t, bid_t>, TPIE_OS_LONGLONG>* out, SCAN_FLAG* sfout) {
pair<rectangle<coord_t, bid_t>, TPIE_OS_LONGLONG>* /* out */, SCAN_FLAG* sfout) {
// Write nothing to the output stream.
*sfout = false;
if (*sfin) {
Expand Down Expand Up @@ -106,7 +106,7 @@ class scan_scaleAndComputeHilbertValue : public scan_object {

err operate(const rectangle<coord_t, bid_t>& in, SCAN_FLAG* sfin,
pair<rectangle<coord_t, bid_t>, TPIE_OS_LONGLONG>* out, SCAN_FLAG* sfout) {
if ((*sfout = *sfin)) {
if ((*sfout = *sfin) != 0) {

// Translate the rectangle by the given offset and
// compute the midpoint in scaled integer coordinates.
Expand Down

0 comments on commit e3d0845

Please sign in to comment.