मैं boost::numeric::ublas::matrix
के साथ एक आव्यूह गुणन को लागू किया है (my full, working boost code देख)मेरे मैट्रिक्स गुणा को धीमा क्यों करता है?
Result result = read();
boost::numeric::ublas::matrix<int> C;
C = boost::numeric::ublas::prod(result.A, result.B);
और मानक एल्गोरिथ्म के साथ एक दूसरे से (full standard code देखें):
vector< vector<int> > ijkalgorithm(vector< vector<int> > A,
vector< vector<int> > B) {
int n = A.size();
// initialise C with 0s
vector<int> tmp(n, 0);
vector< vector<int> > C(n, tmp);
for (int i = 0; i < n; i++) {
for (int k = 0; k < n; k++) {
for (int j = 0; j < n; j++) {
C[i][j] += A[i][k] * B[k][j];
}
}
}
return C;
}
यह मैं कैसे गति का परीक्षण है:
time boostImplementation.out > boostResult.txt
diff boostResult.txt correctResult.txt
time simpleImplementation.out > simpleResult.txt
diff simpleResult.txt correctResult.txt
दोनों प्रोग्राम एक हार्ड-कोडेड टेक्स्टफाइल पढ़ते हैं जिसमें दो 2000 x 2000 matri सीईएस। दोनों कार्यक्रमों इन झंडे के साथ संकलित किया गया:
g++ -std=c++98 -Wall -O3 -g $(PROBLEM).cpp -o $(PROBLEM).out -pedantic
मैं अपने कार्यान्वयन के लिए और बढ़ावा-कार्यान्वयन के लिए से अधिक 4 मिनट15 सेकंड मिल गया है!
संपादित करें:
g++ -std=c++98 -Wall -pedantic -O3 -D NDEBUG -DBOOST_UBLAS_NDEBUG library-boost.cpp -o library-boost.out
साथ यह संकलन करने के बाद मैं 28.19 सेकंड ikj-एल्गोरिथ्म के लिए और 60.99 सेकंड बूस्ट के लिए मिला है। तो बूस्ट अभी भी काफी धीमी है।
मेरे कार्यान्वयन से इतना धीमा क्यों है?
केवल समय पहिया पुनर्रचना एक अच्छा विचार है जब आप एक बेहतर पहिया कर सकते हैं ... – Mysticial
Boost.uBLAS एक मानक _interface_, नहीं एक मजबूत _implementation_ करने के लिए है, तो यह तेजी से जब तक होने की उम्मीद नहीं है है आप उदाहरण का उपयोग कर रहे हैं लापैक बैक एंड। – ildjarn
बूस्ट यूबीएलएएस में कुछ वैकल्पिक डीबग जांच है जो चीजों को धीमा कर देगी। यह FAQ देखें http://www.boost.org/doc/libs/1_49_0/libs/numeric/ublas/doc/index.htm, और प्रीप्रोसेसर मैक्रोज़ BOOST_UBLAS_NDEBUG और NDEBUG – TJD