尝试创建随机整数向量时的OpenMPI编译器错误

openMPI Compiler error when trying to create vector of random Integers

本文关键字:OpenMPI 编译器 错误 向量 创建 随机 整数      更新时间:2023-10-16

我正在尝试创建一个随机整数的向量,但是当我尝试使用mpic++编译时,它会出现一个错误,使我相信我的编译器不喜欢#include <random>。以下是我正在尝试编译的代码。

#include <stdio.h>
#include <stdlib.h>
#include <random>
#include <vector>
#include <algorithm>
#include <map> 
using namespace std;
int main(int argc, char **argv)
{
    vector<int> vec(5);
    random_device rd;
    mt19937 gen(rd());
    uniform_int_distribution<> dis;
    generate(vec.begin(), vec.end(), [&](){ return dis(gen); });
    return 0;
}

我正在使用openmpi,因为它是使用它的较大程序的一部分,但问题在于代码的这一部分。以下是我用来编译的。

mpic++ program.cpp -o program.o

以下是我遇到的错误:

In file included from /usr/include/c++/4.8/random:35:0,
             from program.cpp:3:
/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options

GCC版本是gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)。我可以设置一个标准的标志吗?

编译器建议并使用std标志:

-std=c++11

标题random实际上是C 11扩展。此问题与OpenMPI无关。