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)
- Tasks are dispatched with invalid ranges HOT 3
- Add example for pushing lots of tasks without stalling main thread
- Support for custom asserts HOT 7
- Warning regarding padding with VS 2019 16.11.7 HOT 3
- Using TaskScheduler across DLLs HOT 3
- Compile warnings related to std::is_pod HOT 2
- adding enkiTS as a static library to another project HOT 2
- Running tasks via WaitForTask(NULL) HOT 2
- Scheduling tasks with high priority after-the-fact HOT 5
- Crash when executing a small dependency graph in tight loop HOT 4
- Linking with C HOT 1
- Q: Manual partitioning HOT 6
- Add Github Actions HOT 1
- Feature Request: Shutdown HOT 7
- Make gtl_threadNum invalid by default. HOT 9
- 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.