AlphaFramework API  1.0.3
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Properties | List of all members
AlphaFramework.World.Parallel Class Reference

A lightweight implementation of a small subset of Microsoft's Parallel Extensions for .Net 3.5/4.0 that can be used with the earlier .Net/C# 2.0 More...

Inheritance diagram for AlphaFramework.World.Parallel:

Public Member Functions

void Dispose ()
 Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. More...
 

Static Public Member Functions

static void For (int start, int stop, [NotNull, InstantHandle] Action< int > loopBody, CancellationToken cancellationToken=default(CancellationToken))
 Executes a parallel For loop. More...
 
static void ForEach< T > (IEnumerable< T > items, [NotNull, InstantHandle] Action< T > loopBody)
 Executes a parallel Foreach loop. More...
 

Protected Member Functions

virtual void Dispose (bool disposing)
 Disposes resources. More...
 

Properties

static int ThreadsCount [get, set]
 Gets or sets the number of threads used for parallel computations. More...
 

Detailed Description

A lightweight implementation of a small subset of Microsoft's Parallel Extensions for .Net 3.5/4.0 that can be used with the earlier .Net/C# 2.0

This is an analogue of "Microsoft Parallel Extensions to .NET Framework 3.5, June 2008 Community Technology Preview" from: http://www.microsoft.com/downloads/details.aspx?FamilyID=348f73fd-593d-4b3c-b055-694c50d2b0f3&amp;DisplayLang=en It is not a full implementation, and should be deprecated when MEDIT switch to Visual Studio 2010/.Net 4.0 by using the Microsoft/Novell Mono equivalents. Mono already supports the Parallel Extensions.

This class supports the Parallel.For and Parallel.ForEach loop constructs.

See also: http://tirania.org/blog/archive/2008/Jul-26-1.html http://blogs.msdn.com/somasegar/archive/2008/06/02/june-2008-ctp-parallel-extensions-to-the-net-fx.aspx

This should work on any version of C#/.Net that supports generics.

Member Function Documentation

virtual void AlphaFramework.World.Parallel.Dispose ( bool  disposing)
inlineprotectedvirtual

Disposes resources.

Parameters
disposingif set to true, dispose managed resources.
void AlphaFramework.World.Parallel.Dispose ( )
inline

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

static void AlphaFramework.World.Parallel.For ( int  start,
int  stop,
[NotNull, InstantHandle] Action< int >  loopBody,
CancellationToken  cancellationToken = default(CancellationToken) 
)
inlinestatic

Executes a parallel For loop.

Parameters
startLoop start index.
stopLoop stop index.
loopBodyLoop body.
cancellationTokenUsed to signal if the user wishes to cancel the loop before it completes.

The method is used to parallelise for loop by running iterations across several threads. Example usage:

for ( int i = 0; i &lt; 10; i++ )
{
System.Diagnostics.Debug.WriteLine( "i = " + i );
}

can be replaced by:

Parallel.For( 0, 10, delegate( int i )
{
System.Diagnostics.Debug.WriteLine( "i = " + i );
} );

If Parallel.ThreadCount is exactly 1, no threads are spawned.

static void AlphaFramework.World.Parallel.ForEach< T > ( IEnumerable< T >  items,
[NotNull, InstantHandle] Action< T >  loopBody 
)
inlinestatic

Executes a parallel Foreach loop.

Template Parameters
Ttype
Parameters
itemsLoop items.
loopBodyLoop body.

The method is used to parallelise for loop by running iterations across several threads. Example usage:

foreach ( Molecule molecule in molecules )
{
System.Diagnostics.Debug.WriteLine( "molecule.Title = " + molecule.Title );
}

can be replaced by:

Parallel.ForEach{Molecule}( molecules, delegate( Molecule molecule )
{
System.Diagnostics.Debug.WriteLine( "molecule.Title = " + molecule.Title );
} );

If Parallel.ThreadCount is exactly 1, no threads are spawned.

Property Documentation

int AlphaFramework.World.Parallel.ThreadsCount
staticgetset

Gets or sets the number of threads used for parallel computations.

The threads count.

By default the property is number of CPUs, i.e., System.Environment.ProcessorCount. Setting the property to zero also causes it to be reset to this value.


The documentation for this class was generated from the following file: