Intel似乎已經在這方面做了一些工作。
對於其他人:我不這麼認爲。 cppreference says該
一些C++標準庫實現使用表達式模板來實現上的std ::的valarray有效操作(例如GNU的libstdC++和LLVM的libC++)。只有很少的數字是進一步優化的,如在例如。英特爾Parallel Studio。
我也沒有找到任何文檔說明libC++或libstdC++在這方面做了任何事情,通常沒有人隱藏很酷的功能。 :)
考慮到MSVC:我曾經遇到過使用std::valarray
編譯的代碼,但沒有鏈接,因爲微軟「忘記」實現了一些方法。這當然沒有證據,但對我來說,聽起來並不像在那裏發生的任何酷事。我也找不到任何有關特殊功能的文檔。
那麼我們能做些什麼呢?
其一,我們可以使用parallel mode做出的libstdC++並行使用OpenMP以下算法在其認爲有用:
std::accumulate
std::adjacent_difference
std::inner_product
std::partial_sum
std::adjacent_find
std::count
std::count_if
std::equal
std::find
std::find_if
std::find_first_of
std::for_each
std::generate
std::generate_n
std::lexicographical_compare
std::mismatch
std::search
std::search_n
std::transform
std::replace
std::replace_if
std::max_element
std::merge
std::min_element
std::nth_element
std::partial_sort
std::partition
std::random_shuffle
std::set_union
std::set_intersection
std::set_symmetric_difference
std::set_difference
std::sort
std::stable_sort
std::unique_copy
要做到這一點,只需在編譯期間定義_GLIBCXX_PARALLEL
。我覺得這涵蓋了一大堆人們想用數字組成的東西。當然
注意,_GLIBCXX_PARALLEL定義可以改變尺寸和標準類模板,如std ::搜索行爲,因此可以用並聯模式和代碼,如果沒有實例化無並行模式下編譯只編譯鏈接代碼的容器在兩個翻譯單元之間傳遞。並行模式功能具有獨特的連接,不能與普通模式符號混淆。
(來自here。)
另一個可以幫助你並行化的工具是Intel Advisor。這是更先進的,也可以處理你的循環我相信(從來沒有使用它自己),但當然這是專有軟件。
對於線性代數運算,您還可以尋找一個良好的並行LAPACK實現。
更好的參考['std :: valarray'](http://en.cppreference.com/w/cpp/numeric/valarray) – Mgetz
請注意,某些優化是由編譯器完成的,而不是庫(''ftree -parallelize - 環= 4')。 –
@MarcGlisse確實如此,但這些比庫中的實現更難處理。 –