Я хочу распараллелить мою программу на C ++, используя OpenMP.
Прежде чем распараллелить мой код, я попытался сделать что-то с очень простой программой, такой как эта:
#include <iostream>
#include <vector>
#include <omp.h>
int main () {
std::vector<int> v;
std::vector<int> w;
std::cout<<"Serial"<<std::endl;
for (int i=0; i<1000; i++) {
v.push_back(i);
std::cout<<v[i]<<std::endl;
}
std::cout<<"Parallel"<<std::endl;
#pragma omp parallel for
for (int i=0; i<1000; i++) {
w.push_back(i);
std::cout<<w[i]<<std::endl;
}
return 0;
}
Если я не включу "omp.h"
а также "#pragma omp parallel for"
и я выполняю программу с помощью компилятора g ++, т.е.
g++ -std =c++11 -o test main.cpp
программа работает.
Я установил (правильно я думаю :)) компилятор gcc-4.9, но когда я собрал тот же код с параллельными инструкциями, с этой командной строкой:
gcc-4.9 -std=c++11 -fopenmp -o test main.cpp
У меня есть эта ошибка:
Undefined symbols for architecture x86_64:
"std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))", referenced from:
_main in ccQXPTxS.o
_main._omp_fn.0 in ccQXPTxS.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(int)", referenced from:
_main in ccQXPTxS.o
_main._omp_fn.0 in ccQXPTxS.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccQXPTxS.o
"std::ios_base::Init::~Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccQXPTxS.o
"std::__throw_bad_alloc()", referenced from:
__gnu_cxx::new_allocator<int>::allocate(unsigned long, void const*) in ccQXPTxS.o
"std::__throw_length_error(char const*)", referenced from:
std::vector<int, std::allocator<int> >::_M_check_len(unsigned long, char const*) const in ccQXPTxS.o
"std::cout", referenced from:
_main in ccQXPTxS.o
_main._omp_fn.0 in ccQXPTxS.o
"std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
_main in ccQXPTxS.o
_main._omp_fn.0 in ccQXPTxS.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
_main in ccQXPTxS.o
"operator delete(void*)", referenced from:
__gnu_cxx::new_allocator<int>::deallocate(int*, unsigned long) in ccQXPTxS.o
"operator new(unsigned long)", referenced from:
__gnu_cxx::new_allocator<int>::allocate(unsigned long, void const*) in ccQXPTxS.o
(maybe you meant: operator new(unsigned long, void*))
"___cxa_begin_catch", referenced from:
void std::vector<int, std::allocator<int> >::_M_emplace_back_aux<int const&>(int const&) in ccQXPTxS.o
int* std::__uninitialized_copy<false>::__uninit_copy<std::move_iterator<int*>, int*>(std::move_iterator<int*>, std::move_iterator<int*>, int*) in ccQXPTxS.o
"___cxa_end_catch", referenced from:
void std::vector<int, std::allocator<int> >::_M_emplace_back_aux<int const&>(int const&) in ccQXPTxS.o
int* std::__uninitialized_copy<false>::__uninit_copy<std::move_iterator<int*>, int*>(std::move_iterator<int*>, std::move_iterator<int*>, int*) in ccQXPTxS.o
"___cxa_rethrow", referenced from:
void std::vector<int, std::allocator<int> >::_M_emplace_back_aux<int const&>(int const&) in ccQXPTxS.o
int* std::__uninitialized_copy<false>::__uninit_copy<std::move_iterator<int*>, int*>(std::move_iterator<int*>, std::move_iterator<int*>, int*) in ccQXPTxS.o
"___gxx_personality_v0", referenced from:
Dwarf Exception Unwind Info (__eh_frame) in ccQXPTxS.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
Может ли кто-нибудь помочь мне, пожалуйста?
Задача ещё не решена.