-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add topic about "Lazy Initiliazation" pattern to Design patterns #790
Conversation
Signed-off-by: Ilya Isaev <ilya.isaev@intel.com>
Signed-off-by: Ilya Isaev <ilya.isaev@intel.com>
Signed-off-by: Ilya Isaev <ilya.isaev@intel.com>
Signed-off-by: Ilya Isaev <ilya.isaev@intel.com>
Signed-off-by: Ilya Isaev <ilya.isaev@intel.com>
Signed-off-by: Ilya Isaev <ilya.isaev@intel.com>
Signed-off-by: Ilya Isaev <ilya.isaev@intel.com>
Signed-off-by: Ilya Isaev <ilya.isaev@intel.com>
Signed-off-by: Ilya Isaev <ilya.isaev@intel.com>
Signed-off-by: Ilya Isaev <ilya.isaev@intel.com>
ed14366
to
5ebd730
Compare
Signed-off-by: Ilya Isaev <ilya.isaev@intel.com>
Signed-off-by: Ilya Isaev <ilya.isaev@intel.com>
Signed-off-by: Ilya Isaev <ilya.isaev@intel.com>
} | ||
|
||
|
||
.. |image0| image:: Images/image008a.jpg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you remake screenshots so it would have a space above and beneath the figures?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated images.
The cost of operations that take place during the initialization | ||
of the object may be considerably high. In that case, the object | ||
should be initialized only when it is needed. Lazy initialization | ||
is the common tactic that allows implementing such approach. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the common tactic that allows implementing such approach. | |
is the common tactic that allows implementing such an approach. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
.. rubric:: Problem | ||
:class: sectiontitle | ||
|
||
Delay the creation of an object (potentially expensive) until it is accessed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delay the creation of an object (potentially expensive) until it is accessed. | |
Delay the creation of an object, potentially expensive, until it is accessed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
:class: sectiontitle | ||
|
||
Delay the creation of an object (potentially expensive) until it is accessed. | ||
In parallel programming initialization also must be guarded against race conditions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In parallel programming initialization also must be guarded against race conditions. | |
In parallel programming, initialization must also be guarded against race conditions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
The cost of operations that take place during the initialization | ||
of the object may be considerably high. In that case, the object | ||
should be initialized only when it is needed. Lazy initialization |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be initialized only when it is needed. Lazy initialization | |
should be initialized only when needed. Lazy initialization |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (also applicable to the comments below).
.. rubric:: Example | ||
:class: sectiontitle | ||
|
||
The example presented here illustrate implementation of "lazy initialization" for Fibonacci numbers calculation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example presented here illustrate implementation of "lazy initialization" for Fibonacci numbers calculation. | |
This example illustrates the implementation of "lazy initialization" for the calculation of the Fibonacci numbers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is lazy initialization in quotes here but not in the cases above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed quotes.
|
||
An implementation without the use of "lazy initialization" would have *O(2^N)* time complexity due to | ||
the full recursion tree traversal and recalculation of values. Since all the nodes are traversed once, | ||
the tree previously shown becomes a list, making the time complexity *O(N)*. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the tree previously shown becomes a list, making the time complexity *O(N)*. | |
the tree becomes a list, making the time complexity *O(N)*. |
|
||
|
||
The code for the implementation is shown below. Already calculated values are stored in a buffer paired with | ||
``collaborative_once_flag`` and won't be recalculated when ``collaborative_call_once`` is invoked |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``collaborative_once_flag`` and won't be recalculated when ``collaborative_call_once`` is invoked | |
``collaborative_once_flag`` and will not be recalculated when ``collaborative_call_once`` is invoked |
|image1| | ||
|
||
|
||
The code for the implementation is shown below. Already calculated values are stored in a buffer paired with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code for the implementation is shown below. Already calculated values are stored in a buffer paired with | |
Here you can see the code for the implementation. Already calculated values are stored in a buffer paired with |
Signed-off-by: Ilya Isaev <ilya.isaev@intel.com>
…foundation#790) New topic about Lazy initialization pattern and how it can be implemented using oneapi::tbb::collaborative_call_once has been added. Signed-off-by: Ilya Isaev <ilya.isaev@intel.com> (cherry picked from commit 1da8f0d)
* Update pull_request_template.md (#751) Signed-off-by: Alexandra Epanchinzeva alexandra.epanchinzeva@intel.com (cherry picked from commit 4eda0f9) * Update CONTRIBUTING.md (#765) (cherry picked from commit e274a9e) * Documentation update for unpreview `task_handle` and related stuff (#755) * Unpreview task_handle and related stuff Signed-off-by: Anton Potapov <anton.potapov@intel.com> Co-authored-by: Alexandra <alexandra.epanchinzeva@intel.com> (cherry picked from commit fd76f45) * Update conf.py (#774) (cherry picked from commit 6666292) * Actualize documentation about proportional splitting constructor in Range (#728) Actualize documentation about proportional splitting Signed-off-by: Fedotov, Aleksei <aleksei.fedotov@intel.com> (cherry picked from commit e5cbe50) * Update doc structure and add new files (#791) (cherry picked from commit ce0d258) * Instruction for building the docs locally (#778) (cherry picked from commit e386960) * Document a way to flow graph can be attached to arbitrary task_arena (#785) * Document a way to flow graph can be attached to arbitrary task_arena task_arena interface provides mechanisms to guide tasks execution within the arena by setting the preferred computation units or restricting part of computation units. In some cases, you may want to use mechanisms within a flow graph. Signed-off-by: Serov, Vladimir <vladimir.serov@intel.com> Co-authored-by: Aleksei Fedotov <aleksei.fedotov@intel.com> Co-authored-by: Alexandra Epanchinzeva <alexandra.epanchinzeva@intel.com> (cherry picked from commit a938322) * Add topic about "Lazy Initiliazation" pattern to Design patterns (#790) New topic about Lazy initialization pattern and how it can be implemented using oneapi::tbb::collaborative_call_once has been added. Signed-off-by: Ilya Isaev <ilya.isaev@intel.com> (cherry picked from commit 1da8f0d) * Update Get Started Guide (#803) (cherry picked from commit 0502372) * Update intro_gsg.rst (#808) (cherry picked from commit 2c4f282) * Update conf.py (#810) (cherry picked from commit 0a0a592) * TBB DOC : Dev Guide: Task Scheduler Bypass and How Does Task Scheduler Works (#521) * TBB DOC : Dev Guide: Task Scheduler Bypass and How Task Scheduler Works Signed-off-by: Anton Potapov <anton.potapov@intel.com> Co-authored-by: Alexandra <alexandra.epanchinzeva@intel.com> (cherry picked from commit ed9d4b5) * Update intro_gsg.rst (#811) (cherry picked from commit efea993) * Update conf.py (#812) (cherry picked from commit 3859d11) * Update examples.rst (#816) (cherry picked from commit 4aa0b0b) * Update layout.html (#815) (cherry picked from commit 3e352b4) * Update RELEASE_NOTES.md for oneTBB 2021.6 (#835) (cherry picked from commit faaf43c) Co-authored-by: Alexandra <alexandra.epanchinzeva@intel.com> Co-authored-by: Anton Potapov <potapov.slash.co@gmail.com> Co-authored-by: Aleksei Fedotov <aleksei.fedotov@intel.com> Co-authored-by: Vladimir Serov <vladimir.serov@intel.com> Co-authored-by: Ilya Isaev <ilya.isaev@intel.com> Co-authored-by: Anton Potapov <anton.potapov@intel.com>
Description
New topic about "Lazy initialization" pattern and how it can be implemented using
oneapi::tbb::collaborative_call_once
has been added.Type of change
Choose one or multiple, leave empty if none of the other choices apply
Add a respective label(s) to PR if you have permissions
Tests
Documentation
Breaks backward compatibility
Notify the following users
@alexey-katranov @alexandraepan
Other information