Andy
I appreciate everything you’ve said. Here is a new code that mimics what I
need to do. It has the same problem. If you can have a look at the code
would be great.
If not possible so be it… Thanks.
Kony
#include
#include
#include
#include
#include
#include
#include
#include <blitz/array.h>
#include
#include
#include
#include
#include
#include
#include
#include
#include “gestimer.h”
using namespace std;
using namespace blitz;
// const char* delimiters = " \t\n;()"<>:{}[]±=&#.,/\~?";
const char delimiters = " \t\n";
const char* numbers = “0123456789”;
struct Parents {
int sire;
int dam;
int knownParent;
};
class Count {
int i;
public:
Count() : i(0) {}
void operator++(int) { i++; } // Post-increment
int& val() { return i; }
};
typedef map<int, Count> WordMap;
typedef WordMap::iterator WMIter;
void
getTokens(string& stringToModify, vector& vec) {
// Skip delimiters at beginning.
string::size_type lastPos =
stringToModify.find_first_not_of(delimiters, 0);
// Find first “non-delimiter”.
string::size_type pos = stringToModify.find_first_of(delimiters,
lastPos);
while (string::npos != pos || string::npos != lastPos)
{
// Found a token, add it to the vector.
vec.push_back(stringToModify.substr(lastPos, pos - lastPos));
// Skip delimiters. Note the "not_of"
lastPos = stringToModify.find_first_not_of(delimiters, pos);
// Find next "non-delimiter"
pos = stringToModify.find_first_of(delimiters, lastPos);
}
}
void
rewind(ifstream& dataFile, string dataName) {
//rewind the data file - close and open the file
dataFile.close();
dataFile.clear();
dataFile.open(dataName.c_str());
}
//=====================================================================
// File: gestimer.h
// Purpose: Header file for the GESTimer class.
//=====================================================================
// Adapted from Rogue Wave’s RWTimer class
//
// Author: Martin Schweitzer
#ifndef GES_TIMER_H
#define GES_TIMER_H
class GESTimer {
double startTime_;
double stopTime_;
bool isStopped_;
static double absoluteTime();
public:
GESTimer();
double elapsedTime() const;
void reset();
void start();
void stop();
};
#endif /* GES_TIMER_H */
//=====================================================================
// File: gestimer.cpp
// Purpose: Member function definitions for the GESTimer class.
//=====================================================================
#include
#include
//#include “gestimer.h”
GESTimer::GESTimer() :
startTime_(0),
stopTime_(0),
// isStopped_(TRUE)
isStopped_(true) // changed by KK
{
}
double
GESTimer::elapsedTime() const
{
return (isStopped_ ? stopTime_ : absoluteTime()) - startTime_;
}
void
GESTimer::reset()
{
startTime_ = 0;
stopTime_ = 0;
// isStopped_ = TRUE;
isStopped_ = true;
}
void
GESTimer::start()
{
startTime_ = absoluteTime() - elapsedTime();
// isStopped_ = FALSE;
isStopped_ = false;
}
void
GESTimer::stop()
{
stopTime_ = absoluteTime();
// isStopped_ = TRUE;
isStopped_ = true;
}
double
GESTimer::absoluteTime()
{
return (double)clock() / CLOCKS_PER_SEC;
}
int main() {
Array<int,2> dataMatrix, address;
Array<int,1> dataRecord;
Array<double,2> coefficient;
Array<double,3> Rinv;
Array<double,1> p, q, t1, t2;
dataMatrix.resize(5000000,30);
dataRecord.resize(30);
int newNumFactors = 20;
int missingValue = -1;
int numberOfTraits = 9;
int nrow;
address.resize(newNumFactors,numberOfTraits);
coefficient.resize(newNumFactors,numberOfTraits);
Rinv.resize(1000,numberOfTraits,numberOfTraits);
p.resize(10000000);
q.resize(10000000);
t1.resize(numberOfTraits);
t2.resize(numberOfTraits);
for (int i = 0; i < 1000; i++) {
Rinv(i,Range::all(),Range::all()) = 5.0;
}
GESTimer stopwatch;
stopwatch.reset();
stopwatch.start();
dataMatrix = 1;
p = 4.0;
q = 0.0;
int numOfThreads = 5;
//#pragma omp parallel for num_threads(numOfThreads)
#pragma omp parallel
{
#pragma omp for
for (int ir = 0; ir < dataMatrix.rows(); ir++) {
dataRecord(Range::all()) = dataMatrix(ir, Range::all());
nrow = 63;
// find address and design matrix coefficients
// getAddress();
for (int i = 0; i < newNumFactors; i++) {
for (int k = 0; k < numberOfTraits; k++) {
address(i,k) = i + k + 100;
coefficient(i,k) = 0.707;
}
}
// calculate contributions
t1 = 0.0;
for (int i = 0; i < newNumFactors; i++) {
for (int k = 0; k < numberOfTraits; k++) {
if (address(i,k) == missingValue) {continue;}
t1(k) += coefficient(i,k)*p(address(i,k));
}
}
t2 = 0.0;
for (int k = 0; k < numberOfTraits; k++) {
for (int l = 0; l < numberOfTraits; l++) {
t2(k) += Rinv(nrow,k,l)*t1(l);
}
}
for (int i = 0; i < newNumFactors; i++) {
for (int j = 0; j < numberOfTraits; j++) {
if (address(i,j) == missingValue) {continue;}
q(address(i,j)) += coefficient(i,j)*t2(j);
}
}
} // end of data loop
}
stopwatch.stop();
cout << "Time taken to calculate A*p = q is: " <<
stopwatch.elapsedTime() << endl;
return EXIT_SUCCESS;
}
#include
#include
#include
#include
#include
#include
#include
#include <blitz/array.h>
#include
#include
#include
#include
#include
#include
#include
#include
#include “gestimer.h”
using namespace std;
using namespace blitz;
// const char* delimiters = " \t\n;()"<>:{}[]±=&#.,/\~?";
const char delimiters = " \t\n";
const char* numbers = “0123456789”;
struct Parents {
int sire;
int dam;
int knownParent;
};
class Count {
int i;
public:
Count() : i(0) {}
void operator++(int) { i++; } // Post-increment
int& val() { return i; }
};
typedef map<int, Count> WordMap;
typedef WordMap::iterator WMIter;
void
getTokens(string& stringToModify, vector& vec) {
// Skip delimiters at beginning.
string::size_type lastPos =
stringToModify.find_first_not_of(delimiters, 0);
// Find first “non-delimiter”.
string::size_type pos = stringToModify.find_first_of(delimiters,
lastPos);
while (string::npos != pos || string::npos != lastPos)
{
// Found a token, add it to the vector.
vec.push_back(stringToModify.substr(lastPos, pos - lastPos));
// Skip delimiters. Note the "not_of"
lastPos = stringToModify.find_first_not_of(delimiters, pos);
// Find next "non-delimiter"
pos = stringToModify.find_first_of(delimiters, lastPos);
}
}
void
rewind(ifstream& dataFile, string dataName) {
//rewind the data file - close and open the file
dataFile.close();
dataFile.clear();
dataFile.open(dataName.c_str());
}
//=====================================================================
// File: gestimer.h
// Purpose: Header file for the GESTimer class.
//=====================================================================
// Adapted from Rogue Wave’s RWTimer class
//
// Author: Martin Schweitzer
#ifndef GES_TIMER_H
#define GES_TIMER_H
class GESTimer {
double startTime_;
double stopTime_;
bool isStopped_;
static double absoluteTime();
public:
GESTimer();
double elapsedTime() const;
void reset();
void start();
void stop();
};
#endif /* GES_TIMER_H */
//=====================================================================
// File: gestimer.cpp
// Purpose: Member function definitions for the GESTimer class.
//=====================================================================
#include
#include
//#include “gestimer.h”
GESTimer::GESTimer() :
startTime_(0),
stopTime_(0),
// isStopped_(TRUE)
isStopped_(true) // changed by KK
{
}
double
GESTimer::elapsedTime() const
{
return (isStopped_ ? stopTime_ : absoluteTime()) - startTime_;
}
void
GESTimer::reset()
{
startTime_ = 0;
stopTime_ = 0;
// isStopped_ = TRUE;
isStopped_ = true;
}
void
GESTimer::start()
{
startTime_ = absoluteTime() - elapsedTime();
// isStopped_ = FALSE;
isStopped_ = false;
}
void
GESTimer::stop()
{
stopTime_ = absoluteTime();
// isStopped_ = TRUE;
isStopped_ = true;
}
double
GESTimer::absoluteTime()
{
return (double)clock() / CLOCKS_PER_SEC;
}
int main() {
Array<int,2> dataMatrix, address;
Array<int,1> dataRecord;
Array<double,2> coefficient;
Array<double,3> Rinv;
Array<double,1> p, q, t1, t2;
dataMatrix.resize(5000000,30);
dataRecord.resize(30);
int newNumFactors = 20;
int missingValue = -1;
int numberOfTraits = 9;
int nrow;
address.resize(newNumFactors,numberOfTraits);
coefficient.resize(newNumFactors,numberOfTraits);
Rinv.resize(1000,numberOfTraits,numberOfTraits);
p.resize(10000000);
q.resize(10000000);
t1.resize(numberOfTraits);
t2.resize(numberOfTraits);
for (int i = 0; i < 1000; i++) {
Rinv(i,Range::all(),Range::all()) = 5.0;
}
GESTimer stopwatch;
stopwatch.reset();
stopwatch.start();
dataMatrix = 1;
p = 4.0;
q = 0.0;
int numOfThreads = 5;
//#pragma omp parallel for num_threads(numOfThreads)
#pragma omp parallel
{
#pragma omp for
for (int ir = 0; ir < dataMatrix.rows(); ir++) {
dataRecord(Range::all()) = dataMatrix(ir, Range::all());
nrow = 63;
// find address and design matrix coefficients
// getAddress();
for (int i = 0; i < newNumFactors; i++) {
for (int k = 0; k < numberOfTraits; k++) {
address(i,k) = i + k + 100;
coefficient(i,k) = 0.707;
}
}
// calculate contributions
t1 = 0.0;
for (int i = 0; i < newNumFactors; i++) {
for (int k = 0; k < numberOfTraits; k++) {
if (address(i,k) == missingValue) {continue;}
t1(k) += coefficient(i,k)*p(address(i,k));
}
}
t2 = 0.0;
for (int k = 0; k < numberOfTraits; k++) {
for (int l = 0; l < numberOfTraits; l++) {
t2(k) += Rinv(nrow,k,l)*t1(l);
}
}
for (int i = 0; i < newNumFactors; i++) {
for (int j = 0; j < numberOfTraits; j++) {
if (address(i,j) == missingValue) {continue;}
q(address(i,j)) += coefficient(i,j)*t2(j);
}
}
} // end of data loop
}
stopwatch.stop();
cout << "Time taken to calculate A*p = q is: " <<
stopwatch.elapsedTime() << endl;
return EXIT_SUCCESS;
}
#include
#include
#include
#include
#include
#include
#include
#include <blitz/array.h>
#include
#include
#include
#include
#include
#include
#include
#include
#include “gestimer.h”
using namespace std;
using namespace blitz;
// const char* delimiters = " \t\n;()"<>:{}[]±=&#.,/\~?";
const char delimiters = " \t\n";
const char* numbers = “0123456789”;
struct Parents {
int sire;
int dam;
int knownParent;
};
class Count {
int i;
public:
Count() : i(0) {}
void operator++(int) { i++; } // Post-increment
int& val() { return i; }
};
typedef map<int, Count> WordMap;
typedef WordMap::iterator WMIter;
void
getTokens(string& stringToModify, vector& vec) {
// Skip delimiters at beginning.
string::size_type lastPos =
stringToModify.find_first_not_of(delimiters, 0);
// Find first “non-delimiter”.
string::size_type pos = stringToModify.find_first_of(delimiters,
lastPos);
while (string::npos != pos || string::npos != lastPos)
{
// Found a token, add it to the vector.
vec.push_back(stringToModify.substr(lastPos, pos - lastPos));
// Skip delimiters. Note the "not_of"
lastPos = stringToModify.find_first_not_of(delimiters, pos);
// Find next "non-delimiter"
pos = stringToModify.find_first_of(delimiters, lastPos);
}
}
void
rewind(ifstream& dataFile, string dataName) {
//rewind the data file - close and open the file
dataFile.close();
dataFile.clear();
dataFile.open(dataName.c_str());
}
//=====================================================================
// File: gestimer.h
// Purpose: Header file for the GESTimer class.
//=====================================================================
// Adapted from Rogue Wave’s RWTimer class
//
// Author: Martin Schweitzer
#ifndef GES_TIMER_H
#define GES_TIMER_H
class GESTimer {
double startTime_;
double stopTime_;
bool isStopped_;
static double absoluteTime();
public:
GESTimer();
double elapsedTime() const;
void reset();
void start();
void stop();
};
#endif /* GES_TIMER_H */
//=====================================================================
// File: gestimer.cpp
// Purpose: Member function definitions for the GESTimer class.
//=====================================================================
#include
#include
//#include “gestimer.h”
GESTimer::GESTimer() :
startTime_(0),
stopTime_(0),
// isStopped_(TRUE)
isStopped_(true) // changed by KK
{
}
double
GESTimer::elapsedTime() const
{
return (isStopped_ ? stopTime_ : absoluteTime()) - startTime_;
}
void
GESTimer::reset()
{
startTime_ = 0;
stopTime_ = 0;
// isStopped_ = TRUE;
isStopped_ = true;
}
void
GESTimer::start()
{
startTime_ = absoluteTime() - elapsedTime();
// isStopped_ = FALSE;
isStopped_ = false;
}
void
GESTimer::stop()
{
stopTime_ = absoluteTime();
// isStopped_ = TRUE;
isStopped_ = true;
}
double
GESTimer::absoluteTime()
{
return (double)clock() / CLOCKS_PER_SEC;
}
int main() {
Array<int,2> dataMatrix, address;
Array<int,1> dataRecord;
Array<double,2> coefficient;
Array<double,3> Rinv;
Array<double,1> p, q, t1, t2;
dataMatrix.resize(5000000,30);
dataRecord.resize(30);
int newNumFactors = 20;
int missingValue = -1;
int numberOfTraits = 9;
int nrow;
address.resize(newNumFactors,numberOfTraits);
coefficient.resize(newNumFactors,numberOfTraits);
Rinv.resize(1000,numberOfTraits,numberOfTraits);
p.resize(10000000);
q.resize(10000000);
t1.resize(numberOfTraits);
t2.resize(numberOfTraits);
for (int i = 0; i < 1000; i++) {
Rinv(i,Range::all(),Range::all()) = 5.0;
}
GESTimer stopwatch;
stopwatch.reset();
stopwatch.start();
dataMatrix = 1;
p = 4.0;
q = 0.0;
int numOfThreads = 5;
//#pragma omp parallel for num_threads(numOfThreads)
#pragma omp parallel
{
#pragma omp for
for (int ir = 0; ir < dataMatrix.rows(); ir++) {
dataRecord(Range::all()) = dataMatrix(ir, Range::all());
nrow = 63;
// find address and design matrix coefficients
// getAddress();
for (int i = 0; i < newNumFactors; i++) {
for (int k = 0; k < numberOfTraits; k++) {
address(i,k) = i + k + 100;
coefficient(i,k) = 0.707;
}
}
// calculate contributions
t1 = 0.0;
for (int i = 0; i < newNumFactors; i++) {
for (int k = 0; k < numberOfTraits; k++) {
if (address(i,k) == missingValue) {continue;}
t1(k) += coefficient(i,k)*p(address(i,k));
}
}
t2 = 0.0;
for (int k = 0; k < numberOfTraits; k++) {
for (int l = 0; l < numberOfTraits; l++) {
t2(k) += Rinv(nrow,k,l)*t1(l);
}
}
for (int i = 0; i < newNumFactors; i++) {
for (int j = 0; j < numberOfTraits; j++) {
if (address(i,j) == missingValue) {continue;}
q(address(i,j)) += coefficient(i,j)*t2(j);
}
}
} // end of data loop
}
stopwatch.stop();
cout << "Time taken to calculate A*p = q is: " <<
stopwatch.elapsedTime() << endl;
return EXIT_SUCCESS;
}