“并发”:具有该名称的名称空间不存在 [英] 'Concurrency': a namespace with this name does not exist

查看:110
本文介绍了“并发”:具有该名称的名称空间不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名业余C#程序员,由于需要C ++ AMP技术来执行一些繁重的数字运算,因此他们迷上了C ++。因此,我的C ++编程技能不是很发达。



第一次尝试实际程序时,我选择了基于丹尼尔·莫斯(Daniel Moth)2012年4月的文章。我无法建立它。我总是收到错误消息:


C2871'并发':不存在具有该名称的名称空间。


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


C3861:'access'找不到标识符,文件'amp.h'中的第2616行。


所以我再次开始,这次使用一个空的Windows Console应用项目。再次,我不得不对代码进行大量调整才能从Visual Studio 11迁移到VS 2017,但最终得到如下所示的代码。



我尽力找到了错误的来源。我同时针对x64和x86,但没有区别。我注释掉了第5行和第21 – 27行,代码将生成并执行。 IntelliSense没有出现任何问题,无论是标识符还是语法。实际上,鼠标悬停信息可以识别 Concurrency 构造。我故意拼写 Concurrency ,但是IntelliSense很快就抓住了它。我查看了项目属性,着眼于需要更改以运行AMP的设置,但是由于我什至不确定自己在寻找什么,所以我什么也没找到。



我试图找到定义了 Concurrency 的文件的名称,以便我可以搜索我的机器以查看它是否在那里,并且添加一条路径(如果成功),但未成功。我什至找不到文件名。我通过谷歌搜索和搜索了在线资源和MS Docs,但是无论我如何用短语表达搜索问题,都找不到任何答案。



错误提示:


并发不存在


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



我的机器是Win 7 SP1机器。已安装 KB2999226 错误修复程序。由于我只对C#和C ++感兴趣,所以我没有安装VS 2017的全部。我没有安装我应该拥有的东西吗?



如果以前已解决此问题,我将找不到它。因此,我们将不胜感激。

  1。 #include& h> 
2. #include pch.h
3. #include< iostream>
4. #include< vector>
5.使用名称空间并发;
6.
7. int main(){
8. const int M = 1024; const int N = 1024; //行,向量
的col9。std :: vector< int> vA(M * N); std :: vector< int> vB(M * N); //添加
10的向量。std :: vector< int> vC(M * N); //结果的向量
11。
12. for(int i = 0; i< M; i ++){vA [i] = i; } //填充向量
13. for(int j = N-1; j> = 0; j--){vB [j] = j; }
14.
15. for(int i = 0; i< M; i ++){//
16.的串行版本,用于(int j = 0; j< N ; j ++){//矩阵加法
17. vC [i * N + j] = vA [i * N + j] + vB [i * N + j]; //使用向量
18.}
19.}
20.
21.程度上< 2> e(M,N); //使用AMP构造,但不使用
22。array_view< int,2> a(e,vA),b(e,vB); //调用了
并行函数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并发:具有该名称的名称空间不存在。第5行
31。//所有并发对象的C2065,C3861,C2062第21行-第27行
32。}
33.


解决方案

使用,

  #include amp.h 
#include pch.h
#include< iostream>
使用名称空间并发;

我明白了,

  C2871'concurrency':不存在具有该名称的名称空间

但是,

  #include pch.h 
#include< iostream>
#include amp.h
使用名称空间并发;

没有错误。



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



我也同时使用了并发并发。没有区别。






对于错误 C3861:找不到访问标识符,行文件 amp.h中为2616。



从菜单中选择 Project ,然后选择属性



属性页面中窗口,在 C / C ++ 下,选择所有选项,然后选择一致性模式



是(/ permissive-)更改为。选择 OK



构建项目并运行。



<默认情况下,/ permissive-选项在由Visual Studio 2017 15.5版和更高版本创建的新项目中设置。在早期版本中,默认情况下未设置。设置此选项后,当您的代码中检测到非标准语言构造时,包括在C ++ 11之前的代码中的一些常见错误,编译器就会生成诊断错误或警告。



可能会找到更多信息此处



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


I am an amateur C# programmer who strayed into C++ because of a need for the C++ AMP technology for some heavy-duty number crunching. Hence, my C++ programming skills are not very well developed.

For my first attempt at an actual program, I chose code based on a Daniel Moth's April 2012 article. I cannot get it to build. I always get the error:

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

I know that the code was first written for Visual Studio 11, but I only had VS 2008 and VS 2010 on my machine. So, I installed VS 2017 (version 15.9.4, .Net 4.7.03062). I started with an empty C++ project but had trouble with it. The best I could do, after I worked through all the things it didn’t recognize, was an error:

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

So I started again, this time with an empty Windows Console Application project. Again, I had to tweak the code considerably to migrate from Visual Studio 11 to VS 2017, but ended up with code as shown below.

I tried what I could to find the source of the error. I targeted both x64 and x86, but it made no difference. I commented out line 5 and lines 21 – 27, and the code would build and execute. IntelliSense showed no problems, either with identifiers or syntax. In fact, the mouse-over info recognized the Concurrency constructs as such. I deliberately misspelled Concurrency, but IntelliSense caught that right away. I looked through the project properties with an eye toward a setting that needed to be changed to run AMP, but as I wasn’t even sure what I was looking for, I didn’t find anything.

I tried to find the name of the file in which Concurrency is defined, so that I could search my machine to see if it was there, and to add a path if it was, but was unsuccessful. I couldn’t even find the file name. I googled and pored through on-line sources and MS Docs, but no matter how I phrased my search questions, I didn’t find any answers.

The error says:

Concurrency does not exist

which to me means it can’t find it, it’s not on the machine, or some build setting is preventing it from being used. Most of the on-line articles about writing AMP code say nothing about build settings. Does it not require anything different than a serially-coded project? Is it as simple as a missing reference? If so, where do I go to find it? With my limited experience, I don’t know what else to try.

My machine is a Win 7 SP1 box. The KB2999226 bug fix has been installed. I didn’t install all of VS 2017 since I am only interested in C# and C++. Did I fail to install something I should have?

If this problem was addressed before, I couldn’t find it. So, any help would be appreciated.

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. 

解决方案

With,

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

I get,

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

However, with,

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

there is no error.

I suggest moving #include "amp.h" as shown.

I also used both concurrency and Concurrency. There was no difference.


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

From the menu, select Project, then select Properties.

In the Property Pages window, under C/C++, select All Options, then select Conformance mode.

Change Yes (/permissive-) to No. Select OK.

Build the project and run.

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.

More information may be found here.

This suggests, to me, that "amp.h" is not conforming to the changes made to C++ 15.5. Thus it worked with C++ in VS 2015 14.0 (Update 3), then failed with C++ in VS 2017 15.9.5.

这篇关于“并发”:具有该名称的名称空间不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆