bobcheng15
    • 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
    • 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 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
    # HW5 N Body ###### tags: `平行計算概論2021 spring` [TOC] ## Change Log * Add argument -c2 to srun ## Due Date Mon, 2021/6/7 23:59 ## Introduction * Simulation of a dynamical system of particles Under the influence of gravity * The dataset is an imitation of our Milky Way galaxy In this homework, your are asked to use CUDA with 2 GPUs to perform the simulation. ## Problem Description Please refer to the homework slides for problem description. ## Formulas & Parameters ### Gravity Simulation 1. Calculating the force vector on body $i$ cuased by body $j$: $$f_{ij} = \frac{Gm_im_j}{||q_j - q_i||^2} \cdot \frac{q_j - q_i}{||q_j - q_i||} = \frac{Gm_im_j(q_j - q_i)}{||q_j - q_i||^3}$$ 2. Calculating total force vector on body $i$ caused by other $N - 1$ bodies: $$F_i = \sum_{j \neq i} f_{ij} = \sum_{j \neq i} \frac{Gm_im_j(q_j - q_i)}{||q_j - q_i||^3}$$ 3. To avoid the gravitational force growing indefinitely in situation when two bodies com too close, we add a softening factor $\varepsilon$: $$F_i \approx \sum_{j \neq i} f_{ij} = \sum_{j \neq i} \frac{Gm_im_j(q_j - q_i)}{(||q_j - q_i||^2 + \varepsilon^2)^{ \frac{3}{2}}}$$ 5. Update velocities by: $$v_i(t) = v_i(t-\Delta t) + a_i(t) \cdot \Delta t$$ 6. Update position by: $$q_i(t) = q_i(t - \Delta t) + v_i(t) \cdot \Delta t$$ ## Parameters * Simulation steps: 200000 * Time difference between each time step(sec): $\Delta t = 60$ * Softening factor(m): $\varepsilon = 10^{-3}$ * Gravity constant($m^3kg^{-1}s^{-2}$): $G = 6.674 * 10^{-11}$ * Gravity devices’ mass (kg): $m(t) = m(0) + 0.5 \cdot m(0) \cdot |\sin{\frac{t}{6000}}|$ * The asteroid hits the planet if their distance at a time step is below(m):$10^7$ * Missile traveling speed($m/s$): $10^6$ * Missile cost: $10^5 + 10^3t$ where $t$ is the time the missile reach the asteroid. **All the units given above are SI units, so you don’t need to do conversion. (If you find otherwise, it’s a bug! Please let the TAs know)** ## I/O ### Compilation We will compile your program with a command equivalent to: ``` make ``` ### Command Line Format Your program will be tested with a command equivalent to: ``` srun -pipc21 -c2 --gres=gpu:2 ./hw5 input-file output-file ``` ### Input Format The input is a text file looking like this: ``` N planet-id asteroid-id qx0 qy0 qz0 vx0 vy0 vz0 m0 type0 qx1 qy1 qz1 vx1 vy1 vz1 m1 type1 qx2 qy2 qz2 vx2 vy2 vz2 m2 type2 ... ``` The first line of the input file contains three integers, which are: 1. $N$, the number of celestial bodies. 2. $ID_{planet}$ the (0-indexed ) ID of the planet. 3. $ID_{asteroid}$, the ID of the asteroid. Then there are N lines following, each contains 8 values: 1. $q_{xi}(0), q_{yi}(0), q_{zi}(0)$: the initial position of the i-th body, ```double```. 2. $v_{xi}(0), v_{yi}(0), v_{zi}(0)$: the initial velocity of the i-th body, ```double```. 3. $m_{i}(0)$: the initial mass of the body, ```double```. 4. $type_i$: the type of the body,```string```. ### Output Format The output is a text file looking like this: ``` min-dist hit-time-step gravity-device-id missile-cost ``` * The first line is the minimal distance between the asteroid and the planet if there were no gravity devices. This value is considered correct if the relative error is within $10^{-8}$. * The second line is the time step that the asteroid hit the planet. If the asteroid did not hit the planet, output -2. This value is considered correct if the absolute error is within $\pm 1$ . * The third line contains two numbers. ```gravity-device-id``` is the ID of the gravity device that we want to destroy, ```missile-cost``` is the cost of the missile. If there is no need to destroy the gravity devices, output -1 0. If destroying one gravity device couldn’t prevent the asteroid hitting the planet, output -1 0 as well. missile-cost is considered correct if the relative error is within $10^{-8}$. ## Report Answer the following questions, in either English or Traditional Chinese. 1. What is your parallelism strategy? 2. If there are 4 GPUs instead of 2, what would you do to maximize the performance? 3. If there are 5 gravity devices, is it necessary to simulate 5 n-body simulations independently for this problem? 4. (Optional) Any suggestions or feedback for the homework are welcome. ## Submission Upload these files to iLMS: * ```hw5.cu``` – the source code of your implementation. * ```Makefile``` – optional. Submit this file if you want to change the build command. If you didn’t submit this file, ```/home/ipc21/ta/hw5/Makefile``` will be used. 3. ```report.pdf``` – your report. Please follow the naming listed above carefully. Failing to adhere to the names above will result to points deduction. ## Grading 1. (40%) Correctness. 2. (40%) Performance. Based on the total time you solve all the test cases. 3. (20%) Report. ## Resources Refer to ```/home/ipc21/ta/hw5/``` on hades for sample test cases, source codes and tools. ## Judge The hw5-judge command can be used to automatically judge your code against all sample test cases, it also submits your execution time to the scoreboard so you can compare your performance with others. The scoreboard is [here](https://apollo.cs.nthu.edu.tw/ipc21/scoreboard/hw5/). To use it, run ```hw5-judge``` in the directory that contains your code ```hw5.cu```. It will automatically search for ```Makefile``` and use it to compile your code, or fallback to the TA provided ```/home/ipc21/ta/hw5/Makefile``` otherwise. If code compiliation is successful, it will then run all the sample test cases, show you the results as well as update the scoreboard. ## Judge Verdict Table |Verdict | Explaination| |------- | ------------| |internal error| there is a bug in your code | |time limited exceeded+|execution time > time limit + 10 seconds| |time limited exceeded|execution time > time limit| |runtime error|your program didn’t return 0 or is terminated by a signal| |no output|your program did not produce an output| |wrong answer|your output is incorrect| |accepted|you passed the test case|

    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