Git Product home page Git Product logo

Comments (4)

dougbinks avatar dougbinks commented on June 10, 2024 1

The ExecuteRange virtual function of an ITaskSet provides a parallel_for style interface, as does the TaskSet version which takes a lambda function.

So for example if you have a simple for loop such as:

for( int i = 0; i < count; ++i )
{
     a[i] = b[i] * c[i];
}

you can replace this with a lambda TastSet with set size equal to count, and the following task implementation:

// following is untested code
enki::TaskScheduler g_TS;
g_TS.Initialize();

enki::TaskSet task( 1024, [&]( enki::TaskSetPartition range, uint32_t threadnum  )
{  
    for( uint64_t i = range_.start; i < range_.end; ++i )
    {
         a[i] = b[i] * c[i];
    }
} );

g_TS.AddTaskSetToPipe( &task );
g_TS.WaitforTask( &task );

You could create a function which takes a lambda and does the above (except for initializing enkiTS which should usually be done only once).

from enkits.

dougbinks avatar dougbinks commented on June 10, 2024 1

For the C API you can't use lambda's, but instead you use a simple function, take a look at the ParallelSum_c and the following based on the above example:

// warning untested code

void ParallelTaskSetFunc( uint32_t start_, uint32_t end_, uint32_t threadnum_, void* pArgs_ )
{
    for( uint64_t i = range_.start; i < range_.end; ++i )
    {
         // a, b, c are globals here, but you could pass them via pArgs_
         a[i] = b[i] * c[i];
    }
}

enkiTaskScheduler* pETS = enkiNewTaskScheduler();
enkiInitTaskScheduler( pETS );

enkiTaskSet* pParallelTaskSet = enkiCreateTaskSet( pETS, ParallelTaskSetFunc );
struct enkiParamsTaskSet parSumTaskParams = enkiGetParamsTaskSet( pParallelTaskSet );
parSumTaskParams.setSize = count;
enkiSetParamsTaskSet( pParallelTaskSet, parSumTaskParams );

enkiAddTaskSet( pETS, pParallelTaskSet );
enkiWaitForTaskSet( pETS, pParallelTaskSet );

Let me know if you have any further questions.

from enkits.

ib00 avatar ib00 commented on June 10, 2024

Thanks! I presume that TaskSet idea would also work with C API.

from enkits.

ib00 avatar ib00 commented on June 10, 2024

Thanks! With minor modification, I can confirm that both C++ and C versions you gave
work nicely.

I appreciate you making this library available.

from enkits.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.