Ziva Li
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 2021 Parallel Programming HW2 309706008 李欣盈 ### <font color="#0073FF"></font> All plots available at: [PP HW2](https://docs.google.com/spreadsheets/d/10RDkF99o2d82xOlyK9vr0hqzayxay4UyOgTAPRL1lsI/edit?usp=sharing) ## <font color="#0073FF"> Q1 </font> ### <font color="#0073FF">Produce a graph of speedup compared to the reference sequential implementation as a function of the number of threads used for VIEW 1 and VIEW 2. </font> The following figures are speedup and execution time based on different number of threads for view 1 and 2. ### View 1 ![](https://i.imgur.com/CYJxva7.png) ![](https://i.imgur.com/BKNaSLu.png) mandelbrot serial [mandelbrot serial]: [462.395] ms Wrote image file mandelbrot-serial.ppm thread = 2 [mandelbrot thread]: [236.736] ms Wrote image file mandelbrot-thread.ppm (1.95x speedup from 2 threads) thread = 3 [mandelbrot thread]: [283.566] ms Wrote image file mandelbrot-thread.ppm (1.63x speedup from 3 threads) thread = 4 [mandelbrot thread]: [194.707] ms Wrote image file mandelbrot-thread.ppm (2.38x speedup from 4 threads) thread = 8 [mandelbrot thread]: [141.096] ms Wrote image file mandelbrot-thread.ppm (3.27x speedup from 8 threads) thread = 16 [mandelbrot thread]: [127.580] ms Wrote image file mandelbrot-thread.ppm (3.62x speedup from 16 threads) ### View 2 ![](https://i.imgur.com/9960k3a.png) ![](https://i.imgur.com/LL4wAQs.png) mandelbrot serial [mandelbrot serial]: [288.883] ms Wrote image file mandelbrot-serial.ppm thread = 2 [mandelbrot thread]: [172.775] ms Wrote image file mandelbrot-thread.ppm (1.67x speedup from 2 threads) thread = 3 [mandelbrot thread]: [131.590] ms Wrote image file mandelbrot-thread.ppm (2.19x speedup from 3 threads) thread = 4 [mandelbrot thread]: [111.025] ms Wrote image file mandelbrot-thread.ppm (2.60x speedup from 4 threads) thread = 8 [mandelbrot thread]: [79.017] ms Wrote image file mandelbrot-thread.ppm (3.66x speedup from 8 threads) thread = 16 [mandelbrot thread]: [77.061] ms Wrote image file mandelbrot-thread.ppm (3.75x speedup from 16 threads) ### <font color="#0073FF">Is speedup linear in the number of threads used? </font> The speedup for **view 1 is not linear**. We can see that there is a decrease in speedup when number of threads is 3. The speedup for view 2, however, seems to be linear. ### <font color="#0073FF">In your writeup hypothesize why this is (or is not) the case?</font> Because of the different speedup behavior of view 1 and 2, we could possibly deduce that it could be related to **different pattern of the picture**. We can see that, in view 1, there're more white pixels and the position of those white pixels are more close to each other. ![](https://i.imgur.com/VNcIRFI.png) According to the explanation of [drawing the Mandelbrot set](https://jonisalonen.com/2013/lets-draw-the-mandelbrot-set/). > Plotting the Mandelbrot set is easy: map each pixel on the screen to a complex number, check if it belongs to the set by iterating the formula, and color the pixel black if it does and white if it doesn’t. Since the iteration may never end we set a maximum In our code, the `mandel` function will decide the color of a pixel. The `count` is equal to `maxIterations`, which is 256. The calculation inside the for loop shown below will be executed ranging from 0-255 times. 0 represents black and 255 represents white. If a pixel shoud be painted white, the for loop will be executed more times as compare to a black pixel. ![](https://i.imgur.com/lRuAQLS.png) Due to the use of spatial decomposition, **the execution time of region with more white pixels could be higher**. This could possibly be related to the non-linear speedup behavior of view 1 using 3 threads. The middle part of the view 1 contains lots of white pixels and tasks are not equally divided to all 3 threads. The execution time of one of the thread will be higher, which results in the overall degraded speedup. ## <font color="#0073FF"> Q2 </font> ### <font color="#0073FF">Measure the amount of time each thread requires to complete its work. </font> ### View 1 We noticed a degraded speedup when thread number is 3. We stated that this could be related to different workload each thread has. If the area a thread need to compute includes more white pixels, the execution time could be higher. We measure the time taken for each thread using `CycleTimer.h`. The following section shows execution time of each thread when thread number is 2, 3, 4 respectively. The computation regions each thread got are show in the tables. #### 2 Threads * Workload of two threads are equal. Execution time of each thread are basically the same. * Thus, reached approximately 2x (1.95x) speedup. ![](https://i.imgur.com/yp1hUzd.png) Computation area of each thread | Thread 0 | Thread 1 | | -------- | -------- | |![](https://i.imgur.com/vu1QeNW.jpg)|![](https://i.imgur.com/nm4ndRu.jpg)| #### 3 Threads * The area thread 1 needed to compute has way more white pixels as compared to the other 2 threads. Therefore, the execution time of thread 1 is a lot higher than the other two threads. * Due to the slow execution of thread 1, a declined speedup(1.63x) is noticed as compared to thread number is 2. ![](https://i.imgur.com/q9jgxwn.png) Computation area of each thread | Thread 0 | Thread 1 | Thread 2 | | -------- | -------- | -------- | |![](https://i.imgur.com/nIsXAgG.jpg)|![](https://i.imgur.com/v4LmHVr.jpg)|![](https://i.imgur.com/C5zhymB.jpg) #### 4 Threads * The area thread 1 and 2 needed to compute has way more white pixels as cmopared to the other 2 threads. Therefore, thread 1 and 2 takes more time as compared to thread 0 and 3. * The area comtaining more white pixels are equally divided to thread 1 and 2. Two threads collaborated to increase the program performance. Therefore, the speedup (2.38x) is higher compared to thread number is 2 and 3. ![](https://i.imgur.com/qJmT0AR.png) Computation area of each thread | Thread 0 | Thread 1 | Thread 2 | Thread 3 | | -------- | -------- | -------- | -------- | |![](https://i.imgur.com/dQvJuul.jpg)|![](https://i.imgur.com/0fyi85X.jpg)|![](https://i.imgur.com/1DBUSeH.jpg)|![](https://i.imgur.com/idSe5Ch.jpg)| ### <font color="#0073FF"> How do your measurements explain the speedup graph you previously created? </font> Through our experiment, we can conclude that the execution time of each thread is highly related to the ratio of white area it need to compute. In the 3 thread scenario, thread 1 need to compute areas with higher workload (more white pixels), resulting in degraded speedup. So we can divided those high white/black ratio rows to each thread to increase the speedup. ### View 2 We further prove our idea through experiment with view 2. We tried to divided view 2 into four segments. The top region contains more white areas as compared to all the other 3. * Thread 0 received the top area, thus, has higher execution time. ![](https://i.imgur.com/2Jezr8t.png) Computation area of each thread | Thread 0 | Thread 1 | Thread 2 | Thread 3 | | -------- | -------- | -------- | -------- | |![](https://i.imgur.com/xT0d2Ff.jpg)|![](https://i.imgur.com/ze83ROb.jpg)|![](https://i.imgur.com/XEwXpmw.jpg)|![](https://i.imgur.com/XKcCgRk.jpg) ## <font color="#0073FF"> Q3 </font> ### <font color="#0073FF">Resort to decomposition policy. In your write-up, describe your approach to parallelization</font> We can divided those high white/black ratio rows to each thread to increase the speedup. ![](https://i.imgur.com/GiPZRmz.png) In our improved version, the first row each thread needed to compute is its own thread ID, e.g. thread 0 starts from row 0, thread 2 starts from row 2. The following row each thread need to compute is (last computed row + number of threads). For example, there are 3 threads, thread 0 need to compute row 0, 3(0+3), 6(3+3).... We may refer to the figure below for the visualization of this approach. ![](https://i.imgur.com/2Cx7rp1.png) We can assume that there are 10 rows. * Thread 0 is responsible for row [0, 3, 6, 9] * Thread 1 is responsible for row [1, 4, 7] * Thread 2 is responsible for row [2, 5, 8] So instead of dividing the whole picture into 3 sections(as shown below) in the previous approach, we are able to **distribute the middle part of the graph(contains lots of white pixels, higher workload) to different threads**. Through this decoupled task distrubution, we can increase the performance of our calculation. ![](https://i.imgur.com/f1dzZrm.png) ### <font color="#0073FF">Report the final 4-thread speedup obtained </font> ### View 1 3.79x speedup from 4 threads ``` [mandelbrot thread]: [122.095] ms Wrote image file mandelbrot-thread.ppm (3.79x speedup from 4 threads) ``` Compared with the previous implementation(Spatial Decomposition) A: Spatial Decomposition B: Improved Decomposition Policy ![](https://i.imgur.com/xeta5CV.png) ### View 2 3.77x speedup from 4 threads ``` [mandelbrot thread]: [76.626] ms Wrote image file mandelbrot-thread.ppm (3.77x speedup from 4 threads) ``` Compared with the previous implementation(Spatial Decomposition) A: Spatial Decomposition B: Improved Decomposition Policy ![](https://i.imgur.com/vcsIQzz.png) Through comparison with the previous implementation (Spatial Decomposition/Block Partition), we see that we are able to achieve near-linear speedup performance using the improved decomposition policy(red line B). ## <font color="#0073FF"> Q4 </font> ### <font color="#0073FF">Now run your improved code with eight threads. Is performance noticeably greater than when running with four threads?</font> The performance is **a bit degraded** when using 8 threads for both view 1 and view 2. ### View 1 3.79x speedup from 4 threads 3.71x speedup from 8 threads ``` [mandelbrot thread]: [124.697] ms Wrote image file mandelbrot-thread.ppm (3.71x speedup from 8 threads) ``` ### View 2 3.77x speedup from 4 threads 3.70x speedup from 8 threads ``` [mandelbrot thread]: [78.258] ms Wrote image file mandelbrot-thread.ppm (3.70x speedup from 8 threads) ``` ### <font color="#0073FF">Why or why not? (Notice that the workstation server provides 4 cores 4 threads.) </font> The 8 thread speedup is not noticeably greater than that of 4 thread speedup because the workstation server has only 4 cores. If we `lscpu`, we see that the server has 1 CPU sockets, each CPU has, up to 4 cores and each core has 1 threads. The max thread count is, 1 CPU x 4 cores x 1 threads per core, 4. ![](https://i.imgur.com/7b3haJ1.png) Attempting to create more than 4 threads may introduce **context switch overhead**. Each task switch takes a certain amount of time for the CPU to change the process environment. This may reduce the speedup, resulting in higher execution time as compared to using only 4 threads. :::info Excellent! You are the god of reports. Keep going in the future. 💪💪💪 >[name=TA] :::

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully