visual+c+++2010环境下调试并行开发程序

好就没有写自己的技术博客了,信手翻来,发现已是半年前的情形了。漫步网页间,居然搜索到了自己一直关心的咚咚。毕竟还是对C++的那种眷恋,QT也好,TBB也好,Meego也好,都还有有着那份关注。

 

今天看到的这篇文章是从MSDN里摘录下来的,毕竟ppl还是比较新的。相信国内还有很多人未曾使用过这类东东。以前可以用openmp来做多核计算(其实Intel CPU下TBB更好用些),到了vs 2010里完全可以用微软提供的这个ppl.h来做。长话短说,贴上,看到的咚咚。

 

转自:http://msdn.microsoft.com/en-us/library/dd554943.aspx

 

This walkthrough shows how to use the Parallel Tasks andParallel Stacks windows to debug a parallel application. These windows help you understand and verify the runtime behavior of code that uses theTask Parallel Library or theConcurrency Runtime. This walkthrough provides sample code that has built-in breakpoints. After the code breaks, the walkthrough shows how to use theParallel Tasks and Parallel Stacks windows to examine it.

This walkthrough teaches these tasks:

  • How to view the call stacks of all threads in one view.

  • How to view the list of System.Threading.Tasks.Task instances that are created in your application.

  • How to view the real call stacks of tasks instead of threads.

  • How to navigate to code from the Parallel Tasks andParallel Stacks windows.

  • How the windows cope with scale through grouping, zooming, and other related features.

You must have Visual Studio 2010 installed on the computer.

This walkthrough assumes that Just My Code is enabled. On theTools menu, click Options, expand theDebugging node, select General, and then selectEnable Just My Code (Managed only). If you do not set this feature, you can still use this walkthrough, but your results may differ from the illustrations.

C# Sample

If you use the C# sample, this walkthrough also assumes that External Code is hidden. To toggle whether external code is displayed, right-click theName table header of the Call Stack window, and then select or clearShow External Code. If you do not set this feature, you can still use this walkthrough, but your results may differ from the illustrations.

C++ Sample

If you use the C++ sample, you can ignore references to External Code in this topic. External Code only applies to the C# sample.

Illustrations

The illustrations in this topic recorded on a quad core computer running the C# sample. Although you can use other configurations to complete this walkthrough, the illustrations may differ from what is displayed on your computer.

The sample code in this walkthrough is for an application that does nothing. The goal is just to understand how to use the tool windows to debug a parallel application.

To create the sample project

  1. In Visual Studio, on the File menu, point to New and then click Project.

  2. In the Installed Templates pane, select either Visual C#, Visual Basic, or Visual C++. For the managed languages, ensure that .NET Framework 4 is displayed in the framework box.

  3. Select Console Application and then click OK. Remain in Debug configuration, which is the default.

  4. Open the .cpp, .cs, or .vb code file in the project. Delete its contents to create an empty code file.

  5. Paste the following code for your chosen language into the empty code file.

 


#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <ppl.h>
#include <agents.h>
#include <stdio.h>
#include <concrtrm.h>
#include <vector>

CRITICAL_SECTION cs;

using namespace ::std;
using namespace ::std::tr1;
using namespace ::Concurrency;
task_group task4;
task_group task3;
task_group task2;

volatile long aa = 0;
volatile long bb = 0;
volatile long cc = 0;
static bool waitFor1 = true;
static bool waitFor5 = true;

#pragma optimize("", off)
void Spin()
{
 for(int i=0;i<50*50000;++i);
}
#pragma optimize("",on)

template<class Func>
class RunFunc
{
 Func& m_Func;
 int m_o;
public:
 RunFunc(Func func,int o):m_Func(func),m_o(o){

 };
 void operator()()const{
  m_Func(m_o);
 };
};

void T(int o)
{
 cout << "Scheduled run \n";

};

void R(int o)
{
 if (o == 2)
 {
  while (waitFor5) { ;}
  Spin();

  //use up all processors but 4 by scheduling 4 non-terminating tasks.
  int numProcsToBurn = GetProcessorCount() - 4;
  int i;
  vector<call<int>*> tasks;
  for (i = 0; i <  numProcsToBurn; i++)
  {
   tasks.push_back(new call<int>([](int i){while(true)Spin();}));
   asend(tasks[i],1);
   cout << "Started task  \n";
  }

  task_handle<RunFunc<decltype(T)>> t6(RunFunc<decltype(T)>(T,i + 1 + 5));
  task_handle<RunFunc<decltype(T)>> t7(RunFunc<decltype(T)>(T,i + 2 + 5));
  task_handle<RunFunc<decltype(T)>> t8(RunFunc<decltype(T)>(T,i + 3 + 5));
  task_handle<RunFunc<decltype(T)>> t9(RunFunc<decltype(T)>(T,i + 4 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Visual C++ 2010 Express是一款基于Windows操作系统的编程软件,是Visual Studio 2010开发工具套件中的一个组件。它可以帮助开发人员创建高质量的应用程序和服务,支持多种编程语言的开发,并且为Visual C++编写的应用程序提供了许多工具和资源。 Visual C++ 2010 Express具有易于使用和学习的界面,具有许多图形化用户界面设计工具,可以帮助开发人员快速创建高效的Windows应用程序和服务。它还提供了许多模板和示例应用程序,可以为开发人员节省时间和精力,因为他们可以直接使用这些现有的模板和示例应用程序开发自己的项目,而不必从头开始编写。 此外,Visual C++ 2010 Express还包括一些高级功能,如多线程编程、垃圾回收和并行编程。这些功能可以使应用程序更加高效、稳定和可扩展,并提高应用程序的性能和响应速度。 总之,Visual C++ 2010 Express是一款功能丰富、易于使用的编程工具,可以帮助开发人员创建高质量、高效和稳定的Windows应用程序和服务。 ### 回答2: VisualC 2010 Express是一款由微软公司开发的完全免费的轻量级编程工具。该软件集成了非常多的功能和工具,方便开发人员编写高质量的Windows应用程序和游戏。用户可以使用VisualC 2010 Express编写C++、C#、或Visual Basic语言的程序,而且可运行于Windows XP、Windows Vista、Windows 7和Windows 8等多个Windows操作系统平台上。 VisualC 2010 Express提供了一个非常优秀和易于使用的开发环境。它包含了一些方便的模板和库文件以及便于调试的工具。开发人员可以通过使用VisualC 2010 Express,为Windows平台构建高质量的本地应用程序,还可以使用该软件进行多线程编程、Win32编程、MFC应用程序开发等,相比其他编程语言来说,开发效率非常高。 不仅如此,VisualC 2010 Express还允许开发人员访问微软的开发文档,以及使用代码编辑器和智能提示功能等工具,这些工具可以帮助开发人员更加轻松高效地进行开发工作。另外,由于VisualC 2010 Express是完全免费的,所以它也是学生、初学者以及独立开发者的首选编程软件之一。总之,VisualC 2010 Express是一款强大、易于使用、免费的编程工具,对于需要为Windows平台开发应用程序开发人员来说是非常理想的选择。 ### 回答3: Visual C++ 2010 Express是Microsoft公司推出的一款免费开发工具,主要面向初学者和个人开发者。它是Visual Studio系列工具中的一员,具有一些常用的编辑、编译和调试功能。开发者可以使用它来编写Windows应用程序、图形界面、控制台程序Windows服务、动态链接库等各种类型的应用程序。在Visual C++ 2010 Express中,开发者可以快速创建Windows Form应用程序模板,并通过拖放控件的方式创建用户界面。工具还提供了一些常用的代码片段和示例,帮助开发者加快学习和开发进程。此外,Visual C++ 2010 Express还内置了一个调试器,让开发者方便地查找和修复Bug。总之,Visual C++ 2010 Express是一款功能齐全、易于使用,适合初学者和个人开发者的免费开发工具。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值