Comments (4)
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.
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.
Thanks! I presume that TaskSet idea would also work with C API.
from enkits.
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)
- Macro redefinition for WIN32_LEAN_AND_MEAN HOT 1
- Conversion warnings HOT 1
- Wrong asserts used HOT 1
- Suggestions for propagating user data into tasks? Client+Server in same exe HOT 3
- Rejecting a task and adding it back to the queue? HOT 8
- Add soname to shared library HOT 1
- Put header files in a subdirectory HOT 3
- Put header files in a subdirectory in the main repository HOT 2
- Where is the proper position to add PreRun and PostRun? HOT 2
- Race Condition? HOT 3
- The threads responsible for executing the tasks HOT 2
- CMake version HOT 2
- Address Sanitizer finding HOT 1
- Deadlock with WaitForNewPinnedTasks and WaitforAllAndShutdown HOT 4
- Is there a way to prevent some task to run on thread 0 ? HOT 2
- Pin threads on CPU HOT 3
- Run all tasks of given priority (or higher) HOT 3
- Deadlock in SemaphoreWait (macOS) HOT 16
- More platforms supported in enki::GetNumHardwareThreads HOT 5
- Stuttering on Intel hybrid CPUs HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from enkits.