T
Tom
How could adding a local variable to a routine affect the performance
of a valarray in a subsequent call which is also a local.
I have something like the following...
main() {
.....
foo();
}
foo() {
// double a; // if declared then the performance of the valarray
later on is affected, faster, much faster
someFunctionWhichIndirectlyCallsOffendingValarrayCodeManyTimes();
}
OffendingValarrayCode(Widget w) {
valarray<double> params(0., 75);
valarray<double> coeff(0., 75);
for(...) {
// calculate params & coeff filling w/ new values each iter
double r = (params * coeff).sum(); // THIS LINE was the cause
of my grief.
}
}
So I observed several things
1. If I added the local before the call my cumulative run-time to
calculate r is ~14 seconds
2. Without that local declaration the cumulative run-time is about 83
seconds
3. Other combinations of locals could affect as well but I could see
no pattern except time was 83 or 14 seconds
4. Running with a memory bounds/error checker yields no clues.
5. Finally if I correct the calculation of r to the following my
cumulative run-time to calc r went down to 3 seconds
regardless of those locals.
for(size_t k=0, r=0.; k<params.size(); ++k) {
r += params[k] * coeff[k];
}
6. All runs produce identical results which happen to be a matrix 180
x 55 where each cell determined by calculation of r.
So I am not sure how comfortable I should be, is it possible that the
local variable affected something like the cache/paging in some way
which triggered the 83 second run. I have not been able to replicate
this in a simple example so I guess it is possible there is still some
underlying bug but if there were I would think my results would vary.
Thanks,
Tom
of a valarray in a subsequent call which is also a local.
I have something like the following...
main() {
.....
foo();
}
foo() {
// double a; // if declared then the performance of the valarray
later on is affected, faster, much faster
someFunctionWhichIndirectlyCallsOffendingValarrayCodeManyTimes();
}
OffendingValarrayCode(Widget w) {
valarray<double> params(0., 75);
valarray<double> coeff(0., 75);
for(...) {
// calculate params & coeff filling w/ new values each iter
double r = (params * coeff).sum(); // THIS LINE was the cause
of my grief.
}
}
So I observed several things
1. If I added the local before the call my cumulative run-time to
calculate r is ~14 seconds
2. Without that local declaration the cumulative run-time is about 83
seconds
3. Other combinations of locals could affect as well but I could see
no pattern except time was 83 or 14 seconds
4. Running with a memory bounds/error checker yields no clues.
5. Finally if I correct the calculation of r to the following my
cumulative run-time to calc r went down to 3 seconds
regardless of those locals.
for(size_t k=0, r=0.; k<params.size(); ++k) {
r += params[k] * coeff[k];
}
6. All runs produce identical results which happen to be a matrix 180
x 55 where each cell determined by calculation of r.
So I am not sure how comfortable I should be, is it possible that the
local variable affected something like the cache/paging in some way
which triggered the 83 second run. I have not been able to replicate
this in a simple example so I guess it is possible there is still some
underlying bug but if there were I would think my results would vary.
Thanks,
Tom