Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用Mac OS X的openMP和gcc-4.9编译器_C++_Macos_Gcc_Parallel Processing_Openmp - Fatal编程技术网

C++ 使用Mac OS X的openMP和gcc-4.9编译器

C++ 使用Mac OS X的openMP和gcc-4.9编译器,c++,macos,gcc,parallel-processing,openmp,C++,Macos,Gcc,Parallel Processing,Openmp,我想使用OpenMP并行化我的C++程序。 在并行化我的代码之前,我尝试用一个非常简单的程序做一些事情,比如: #include <iostream> #include <vector> #include <omp.h> int main () { std::vector<int> v; std::vector<int> w; std::cout<<"Serial"<<std::en

我想使用OpenMP并行化我的C++程序。 在并行化我的代码之前,我尝试用一个非常简单的程序做一些事情,比如:

#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;
}
这个程序有效

我已经安装了(我想是正确的:)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
架构x86_64的未定义符号:
“std::basic_ostream::operatorTry使用
g++-4.9
?现在它可以工作了!非常感谢!)
    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