'Concurrency': 不存在同名的命名空间

'Concurrency': a namespace with this name does not exist

我是一名业余 C# 程序员,由于某些重型数字 c运行ching 需要 C++ AMP 技术,所以误入了 C++。因此,我的C++编程技能不是很好。

我第一次尝试实际程序时,我选择了基于 Daniel Moth's April 2012 article 的代码。我无法构建它。我总是收到错误消息:

C2871 ‘Concurrency’: a namespace with this name does not exist.

我知道代码最初是为 Visual Studio 11 编写的,但我的机器上只有 VS 2008 和 VS 2010。所以,我安装了 VS 2017(版本 15.9.4,.Net 4.7.03062)。我从一个空的 C++ 项目开始,但遇到了麻烦。在我完成所有它无法识别的事情之后,我能做的最好的是一个错误:

C3861: ‘access’ identifier not found, line 2616 in file ‘amp.h’.

所以我重新开始,这次是一个空的 Windows 控制台应用程序项目。同样,我不得不大幅调整代码以从 Visual Studio 11 迁移到 VS 2017,但最终代码如下所示。

我尽我所能找到错误的根源。我同时针对 x64 和 x86,但没有任何区别。我注释掉了第 5 行和第 21-27 行,代码将构建并执行。 IntelliSense 没有显示任何问题,无论是标识符还是语法。事实上,鼠标悬停信息识别了 Concurrency 构造。我故意拼错 Concurrency,但 IntelliSense 立即捕捉到了。我查看了项目属性,着眼于需要更改为 运行 AMP 的设置,但由于我什至不确定我在寻找什么,所以我没有找到任何东西。

我试图找到其中定义了 Concurrency 的文件的名称,以便我可以搜索我的机器以查看它是否存在,如果存在则添加路径,但没有成功.我什至找不到文件名。我用谷歌搜索并仔细研究了在线资源和 MS 文档,但无论我如何表述我的搜索问题,我都没有找到任何答案。

错误说:

Concurrency does not exist

对我来说这意味着它找不到它,它不在机器上,或者某些构建设置阻止它被使用。大多数关于编写 AMP 代码的在线文章都没有提及构建设置。它不需要与串行编码项目有什么不同吗?它像缺少参考一样简单吗?如果是这样,我应该去哪里找到它?以我有限的经验,我不知道还有什么可以尝试的。

我的机器是Win 7 SP1盒子。 KB2999226 错误修复已安装。我没有安装所有 VS 2017,因为我只对 C# 和 C++ 感兴趣。我是不是没有安装我应该安装的东西?

如果以前解决过这个问题,我找不到了。因此,我们将不胜感激。

1.   #include <amp.h>
2.   #include "pch.h"
3.   #include <iostream>
4.   #include <vector>
5.   using namespace Concurrency;
6.   
7.   int main() {
8.       const int M = 1024; const int N = 1024;            //row, col for vector 
9.       std::vector<int> vA(M*N); std::vector<int> vB(M*N); //vectors to add
10.      std::vector<int> vC(M*N);                          //vector for result
11.   
12.      for (int i = 0; i < M; i++) { vA[i] = i; }         //populate vectors
13.      for (int j = N - 1; j >= 0; j--) { vB[j] = j; }
14.   
15.      for (int i = 0; i < M; i++) {                      //serial version of
16.          for (int j = 0; j < N; j++) {                  //matrix addition
17.              vC[i*N + j] = vA[i*N + j] + vB[i*N + j];   //using vectors
18.          }
19.      }
20.   
21.      extent<2> e(M, N);                         //uses AMP constructs but no
22.      array_view<int, 2> a(e, vA), b(e, vB);     //parallel functions invoked
23.      array_view<int, 2> c(e, vC); 
24.      index<2> idx(0, 0);
25.      for (idx[0] = 0; idx[0] < e[0]; idx[0]++) {
26.          for (idx[1] = 0; idx[1] < e[1]; idx[1]++) {
27.              c[idx] = a[idx] + b[idx];
28.          }
29.      }
30.  // C2871   'Concurrency': a namespace with this name does not exist.  Line 5
31.  // Also C2065, C3861, C2062 for all Concurrency objects    Line 21 - Line 27
32.  }
33. 

有,

#include "amp.h"
#include "pch.h"
#include <iostream>
using namespace concurrency;

我明白了,

C2871   'concurrency': a namespace with this name does not exist

但是,

#include "pch.h"
#include <iostream>
#include "amp.h"
using namespace concurrency;

没有错误。

我建议如图所示移动 #include "amp.h"

我还用了 concurrencyConcurrency。没有区别。


对于错误C3861: ‘access’ identifier not found, line 2616 in file ‘amp.h’.

从菜单中,select Project,然后 select Properties

Property Pageswindow下C/C++,selectAll Options,然后selectConformance mode.

Yes (/permissive-) 更改为 No。 Select OK.

构建项目并运行。

By default, the /permissive- option is set in new projects created by Visual Studio 2017 version 15.5 and later versions. It is not set by default in earlier versions. When the option is set, the compiler generates diagnostic errors or warnings when non-standard language constructs are detected in your code, including some common bugs in pre-C++11 code.

可以找到更多信息 here

对我来说,这表明 "amp.h" 不符合对 C++ 15.5 所做的更改。因此它在 VS 2015 14.0(更新 3)中使用 C++,然后在 VS 2017 15.9.5 中使用 C++ 失败。