Visual Studio 2010 CTP available: Including the Concurrency Runtime, Parallel Pattern Library and Asynchronous Agents Library!

Published 28 October 08 05:09 PM | rickmolloy 

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

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Kenny Kerr said on October 29, 2008 4:36 AM:

Now that the Windows 7 keynote is over we can finally start exploring some of the improvements. This

# Visual Studio Hacks said on October 29, 2008 4:07 PM:

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 ,

# Mattotorang said on January 4, 2009 11:01 AM:

Do you have documentation on the ppl, agents and concrt? Can u share?

# rickmolloy said on January 7, 2009 9:22 PM:

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/

-Rick

# hydguy37 said on January 26, 2009 12:25 AM:

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?

# rickmolloy said on January 26, 2009 12:50 AM:

Unfortunately the .NET 4.0 framework is only available as part of the larger CTP.

# Bek said on June 23, 2009 10:52 AM:

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!

# dmccrady said on June 23, 2009 11:57 AM:

No, it's not possible to use agents.h with VS2008.  It uses features of C++0x that are only supported in VS2010.

# Ainur said on June 24, 2009 4:13 PM:

Hi! Does VS 2010 support BDI architecture?

Leave a Comment

(required) 
(optional)
(required) 

About rickmolloy

I am currently a Program Manager on the Parallel Computing Platform team and I focus on programming models for concurrency in C++.
Page view tracker