سؤال

أقوم بتحويل بعض أكواد الجبر المتجهية الخاصة بي لاستخدام مكتبة uBLAS للدفع المحسن.ومع ذلك ، عندما حاولت القيام بضرب SymmetricMatrix-SparseVector ، وجدت أنه أبطأ بمقدار 4 مرات من تطبيقي الخاص.عادة ما يكون حجم المتجه حوالي 0-500 ويكون حوالي 70-80٪ إدخالات صفر.

هذا هو الكود الخاص بي Genacodicetagpre

يخزن sparseVectorIndexes فهارس القيم غير الصفرية لمتجه الإدخال ، يمثل vectorLength طول المتجه ، و sparseLength هو عدد غير الأصفار في المتجه.يتم تخزين المصفوفة على شكل مصفوفة متناظرة رمز كود رمز عام.

يعد التنفيذ الخاص بي عبارة عن تكرار حلقة متداخلة بسيطة حيث تكون المصفوفة عبارة عن مصفوفة مزدوجة ثنائية الأبعاد فقط: Genacodicetagpre

}

لماذا أبطأ نظام uBLAS 4x؟هل أنا لا أكتب الضرب بشكل صحيح؟أم أن هناك مكتبة أخرى أكثر ملاءمة لذلك؟

تحرير: إذا استخدمت مصفوفة متجهية كثيفة بدلاً من ذلك ، فإن uBLAS يكون أبطأ بمقدار 2x فقط ...

هل كانت مفيدة؟

المحلول

uBlas was not designed with performance as goal No 1 in mind. There are libraries which are significantly faster than uBlas. See e.g. http://eigen.tuxfamily.org/index.php?title=Benchmark

نصائح أخرى

This pdf has quite a detailed comparison of various linear algebra libraries. I came across this in this answer from Computational Science Stack Exchange, which is possibly a better place for this sort of question.

Not sure if it is the cause of the slowdown (did you profile to get your 4x number?) but this loop could be slow:

for(int i = 0; i < vectorLength; i++)
    {
        a[i] = test(i);
    }

If most of the time is spent processing the loops in your code then this extra loop could double the time (and have nothing to do with ublas). I would recommend using std::copy instead:

std::copy(test.begin(), test.end(), a[0])

Most compilers should see that this is copying a double and do an optimal copy, which might fix your problem somewhat.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top