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

时间:2015-02-17 09:15:14

标签: 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::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

有人可以帮我吗?

0 个答案:

没有答案