Visual Studio 2010 CTP available: Including the Concurrency Runtime, Parallel Pattern Library and Asynchronous Agents Library!
In his blog post on Monday, Soma mentioned some of the great things happening at PDC 2008 and also announced the Visual Studio 2010 CTP. We’re very excited to announce that this CTP includes the Concurrency Runtime, the Parallel Pattern and Asynchronous Agents Libraries for C++ developers that we’ve mentioned here and on channel9 previously.
He also announced that the Visual Studio 2010 and .NET 4.0 include the Task Parallel Library, PLINQ and includes parallel profiling and debugging experiences that support both native and managed code.
The CTP is available as a VPC image and is available here:
https://connect.microsoft.com/VisualStudio/content/content.aspx?ContentID=9790
Getting started with the PPL and Agents Library: the walkthrough
Once you have the CTP running, getting started is relatively straightforward. Launch the Visual Studio 2010 CTP and click the link to the walkthroughs. There is one provided which shows a very simple example of using the Parallel Pattern Library and the Agents Library.
Here’s a snippet of that walkthrough, where a parallel_for is used to concurrently check a series of numbers for primality and then sends the prime numbers as a message to an agent. The agent in this example is responsible for inserting them into a vector.
What’s important to take away from this example is how the agents functionality (send, receive and the unbounded_buffer) are used in conjunction with the parallel_for to insert data into a std::vector, which isn’t typically threadsafe. We accomplish this by separating the shared state and in this case the computationally expensive work (IsPrime is slow J) from the less expensive insert operation. It’s also interesting to note, that It may be also useful to just leave those messages in the unbounded_buffer since it supports enqueue and dequeue operations, but in this case we’re assuming there is a need for the random access iteration that std::vector provides.
Here’s the virtual ‘run’ method in the derived ConsumerAgent class below which waits for messages being sent to a message block and then inserts them into a std::vector v:
virtual bool run(){
int curValue;
while(true){
curValue = receive(buf_);
//use -1 to signal exit
if (curValue == -1)
break;
v_.push_back(curValue);
};
return true;
};
And here’s the code which iterates over the range of numbers and sends messages for the agent to process. Note that I’m using a C++ lambda for the body of the loop.
std::vector<int> v;
unbounded_buffer<int> intBuf;
ConsumerAgent myAgent(v,intBuf);
myAgent.start();
parallel_for(1,count,1,[&](int i){
if (IsPrime(i))
send(intBuf,i);
});
//use -1 to signal exit
send(intBuf,-1);
myAgent.wait();
printf("Found %d prime numbers in parallel\n",v.size());
The full example is provided in the walkthrough.
What’s in the CTP: Parallel Pattern Library, Asynchronous Agents Library, Concurrency Runtime
The classes and APIs in the Parallel Pattern Library and Asynchronous Agents Library are in the header files ppl.h and agents.h respectively and all of the APIs are currently in the Concurrency namespace. The Concurrency Runtime itself and the load-balancing scheduler are included as binary code and part of msvcr100.dll in the CTP. Here’s a brief list of the header files and major APIs in each one.
ppl.h: includes parallel_for, parallel_for_each, parallel_invoke, task_group and task_handle
agents.h: includes unbounded_buffer<T>, overwrite_buffer<T>, and the send and receive helper methods. call<T> and transform<Input,Output> and the abstract agent class are also included.
concrt.h: includes APIs for interacting with the scheduler. Note that that it isn’t necessary to interact with the scheduler when you use the APIs and classes in ppl.h or agents.h an implicit scheduler will be created on demand.
I’ll try to take some time over the next couple of days to provide a few examples using each of these APIs on this blog and if you’re at the PDC this week, stop by the Parallel Computing Platform Teams’ booth. We’d love to hear from you.
-Rick
Comments
Anonymous
October 28, 2008
Now that the Windows 7 keynote is over we can finally start exploring some of the improvements. ThisAnonymous
October 29, 2008
My latest in a series of the weekly, or more often, summary of interesting links I come across related to Visual Studio. The Web Developer Team announced that the official IntelliSence documentation file, which provides Rich IntelliSense for jQuery ,Anonymous
January 04, 2009
Do you have documentation on the ppl, agents and concrt? Can u share?Anonymous
January 07, 2009
The CTP has a walkthrough which provides information on using the Concurrency Runtime and the PPL and the header files contain xml documentation. If you have specific questions you're also more than welcome to ask them on the forums http://social.msdn.microsoft.com/Forums/en-US/parallelcppnative/threads/ -RickAnonymous
January 25, 2009
Hi I dont have the necessary infrastructure to download and install Visual Studio 2010 CTP. My machine is WinXP SP2 and I do have a fast broadband connection. I just want to download .NET Framework SDK 4.0 and try out the new stuff. Where can I download just the .NET Framework SDK 4.0 and not the entire Visual Studio 2010 CTP?Anonymous
January 25, 2009
Unfortunately the .NET 4.0 framework is only available as part of the larger CTP.Anonymous
June 23, 2009
Is it possible to transfer agent.h from VS 2010 to VS 2008, so that it would work? I tried it manually (copy, paste), but it didn't work. Thank you!Anonymous
June 23, 2009
No, it's not possible to use agents.h with VS2008. It uses features of C++0x that are only supported in VS2010.Anonymous
June 24, 2009
Hi! Does VS 2010 support BDI architecture?