Search code examples
c++parallel-processingshareagents

Asynchronous Agent Library and data share


I am trying to invoke two independent threads by using Asynchronous Agent Library (AAL) as included in in C++ (refer also to here for AAL description http://msdn.microsoft.com/en-us/library/dd492627.aspx). The Agents Library provides alternatives to shared state by letting you connect isolated components through an asynchronous communication model that is based on dataflow instead of control flow. Dataflow refers to a programming model where computations are made when all required data is available; control flow refers to a programming model where computations are made in a predetermined order.

As I do not want to wait for arbitrary data from one agent, I wanted to use Concurrency::send() and Concurrency::try_receive(). However, I have problems implementing the try_receive method (documentation can be found here http://msdn.microsoft.com/de-de/library/dd470874.aspx).

My current implementation:

ISource<bool>& _source;    
Concurrency::try_receive(_source, &Received,ITarget<CPlant*>::filter_method())

with CPlant as my data to be sent back to the agent where the _source-Message comes from. Agent1 sends a simple boolean "true" and Agent2 (that includes the code mentioned above) responses with the CPlant class. This is working with Concurrency::receive(), but I don't want to block the further execution of the current agent.

Do you have a clue why I get compiling errors like

1>c:\users\robert\tum\da\src\sim\anlagensim\anlagensim\main.cpp(57): error C2782: 'bool Concurrency::try_receive(Concurrency::ISource<_Type> &,_Type &,const ITarget<_Type>::filter_method &)' : template parameter '_Type' is ambiguous
1>          c:\program files\microsoft visual studio 10.0\vc\include\agents.h(16553) : see declaration of 'Concurrency::try_receive'
1>          could be 'int *'
1>          or       'bool'
1>c:\users\robert\tum\da\src\sim\anlagensim\anlagensim\main.cpp(57): error C2780: 'bool Concurrency::try_receive(Concurrency::ISource<_Type> &,_Type &)' : expects 2 arguments - 3 provided

?

Thanks in advance for your help!


Solution

  • I did another approach by using OpenMP that nicely support data sharing and thread management very easily.

    #include <omp.h>
    ...
    
    #pragma omp parallel shared(Simulation, cout) default(none) num_threads(3)
    {
        #pragma omp sections nowait
        {
            #pragma omp section 
            {
            ...
            }
    
            #pragma omp section 
            {
            ...
            }
    
            #pragma omp section
            {
            ...
            }
        }
    }
    

    Be advised to use /openmp switch while using Visual C++.