Welcome to MSDN Blogs Sign in | Join | Help
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

Posted: Tuesday, October 28, 2008 5:09 PM by rickmolloy

Comments

Kenny Kerr said:

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

# October 29, 2008 4:36 AM

Visual Studio Hacks said:

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 ,

# October 29, 2008 4:07 PM

Mattotorang said:

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

# January 4, 2009 11:01 AM

rickmolloy said:

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

# January 7, 2009 9:22 PM

hydguy37 said:

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?

# January 26, 2009 12:25 AM

rickmolloy said:

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

# January 26, 2009 12:50 AM

Bek said:

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!

# June 23, 2009 10:52 AM

dmccrady said:

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

# June 23, 2009 11:57 AM

Ainur said:

Hi! Does VS 2010 support BDI architecture?

# June 24, 2009 4:13 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

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

Page view tracker