代做159.341 – 2024 Semester 1 Assignment 3代写C/C++编程

159.341 – 2024 Semester 1

Assignment 3

Deadline:

Hand in by 5pm on Friday 31st May 2024

Evaluation:

20 marks which is 20% of your final grade

Late Submission:

2 marks off per day late

Work:

This assignment is to be done individually – your submission may be checked for plagiarism against other assignments and against Internet repositories. If you adapt material from the internet you must acknowledge your source.

Purpose:

Develop a parallel implementation of a simulation.

Problem to solve:

A reference (sequential) implementation of an n-body simulator is available on the course stream site. This program simulates the motion of a number of bodies (planets, particles etc) with an attractive force between each pair of particles. Your task is to convert this program to a multi-threaded implementation with the purpose of improving performance.

Description:

You may use whichever multi-threading library/API you choose to convert the simulator to a multi- threaded  implementation  intended  for  a  multi-core  PC. The current implementation is written  in C/C++ but you may write your new implementation in a different programming language if you so choose.

You are free to re-arrange the computation however you see fit; however, the simulator must compute the force between each pair of particles (n2 operations) and perform the calculations using double precision floating-point values. Do not attempt to convert the program to an n log(n) algorithm or similar approximate method.

The state of a body in an n-body simulation consists of a position, velocitymass and radius.

struct body {

vec2 pos;

vec2 vel;

double mass;

double radius;

...

};

The force between each pair of bodies can be calculated by iterating through every pair.

// for each body

for(int i = 0; i < N; ++i) {

// for each following body

for(int j = i+1; j < N; ++j) {

// Calculate force between bodies

...

}

}

The force between two bodies is calculated from their relative positions and masses and accumulated in an array of accelerations.

vec2 dx = bodies[i].pos - bodies[j].pos;      // Difference in position

vec2 u = normalise(dx);                        // Normalised difference in position

double d2 = length2(dx);                       // Distance squared

if(d2 > min2) {                                // If greater than minimum distance

double x = smoothstep(min2, 2 * min2, d2); // Smoothing factor

double f = -G*bodies[i].mass*bodies[j].mass / d2; // Force

acc[i] += (u * f / bodies[i].mass) * x;            // Accumulate acceleration

acc[j] -= (u * f / bodies[j].mass) * x;            // Accumulate acceleration

}

Finally, the new state (position and velocity) of each body can be calculated from the old state, the accumulated acceleration and the timestep dt.

// For each body

for(int i = 0; i < N; ++i) {

bodies[i].pos += bodies[i].vel * dt; // Update Position

bodies[i].vel += acc[i] * dt;        // Update Velocity

}

Details:

The sequential implementation can be compiled into an executable that has a real-time graphics display or a version with no real-time graphics but that writes the final positions and an image to file. The real-time graphics version can be compiled by including the flag -DGRAPHICS and linking to the SFML libraries (available here https://www.sfml-dev.org/).

Requirements:

.    You must provide full details of the language and multi-threaded API you used to develop the implementation (including any version information and any specific flags).

.    Your submission will be marked based on its performance and how effectively it parallelises the program. The performance will be benchmarked on a multi-core machine with a large number of particles (>= 5000).

.    The particle positions produced by your implementation (written to the output file) should be almost the same as the original sequential version. Be aware that there may be slight differences due to floating-point errors (see assignment video for  discussion on expected accuracy).

You must follow the next two specifications in each and every assignment for this course

1.   Place the following comments at the top of your program code and provide the appropriate information:

/* Family Name, Given Name, Student ID, Assignment number, 159.341

*/

/* explain what the program is doing . . . */

2.   Ensure that your main function uses printf to print this information to the console.  You might use code like:

int main( int argc, char * argv[] ){

printf( "----------------------------------------" );

printf( "  159.341 Assignment 3 Semester 1 2023  " );

printf( "  Submitted by: Rick Deckard, 20191187  " );

printf( "----------------------------------------" );

...

}

Hand-in: Submit your program and documentation (a zip file is acceptable) electronically through the form. on the stream site.

Marks will be allocated for: correctness, fitness of purpose, sensible use of data structures and algorithms, utility, style, use of sensible comments and program documentation, and general elegance. Good comments will help me to award you marks even if your code is not quite perfect.


 

 

 

 

;


热门主题

课程名

int2067/int5051 bsb151 babs2202 mis2002s phya21 18-213 cege0012 mgt253 fc021 mdia1002 math39512 math38032 mech5125 cisc102 07 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 efim20036 mn-3503 comp9414 math21112 fins5568 comp4337 bcpm000028 info6030 inft6800 bcpm0054 comp(2041|9044) 110.807 bma0092 cs365 math20212 ce335 math2010 ec3450 comm1170 cenv6141 ftec5580 ecmt1010 csci-ua.0480-003 econ12-200 ectb60h3f cs247—assignment ib3960 tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 econ7230 msinm014/msing014/msing014b math2014 math350-real eec180 stat141b econ2101 fit2004 comp643 bu1002 cm2030 mn7182sr ectb60h3s ib2d30 ohss7000 fit3175 econ20120/econ30320 acct7104 compsci 369 math226 127.241 info1110 37007 math137a mgt4701 comm1180 fc300 ectb60h3 llp120 bio99 econ7030 csse2310/csse7231 comm1190 125.330 110.309 csc3100 bu1007 comp 636 qbus3600 compx222 stat437 kit317 hw1 ag942 fit3139 115.213 ipa61006 econ214 envm7512 6010acc fit4005 fins5542 slsp5360m 119729 cs148 hld-4267-r comp4002/gam cava1001 or4023 cosc2758/cosc2938 cse140 fu010055 csci410 finc3017 comp9417 fsc60504 24309 bsys702 mgec61 cive9831m pubh5010 5bus1037 info90004 p6769 bsan3209 plana4310 caes1000 econ0060 ap/adms4540 ast101h5f plan6392 625.609.81 csmai21 fnce6012 misy262 ifb106tc csci910 502it comp603/ense600 4035 csca08 8iar101 bsd131 msci242l csci 4261 elec51020 blaw1002 ec3044 acct40115 csi2108–cryptographic 158225 7014mhr econ60822 ecn302 philo225-24a acst2001 fit9132 comp1117b ad654 comp3221 st332 cs170 econ0033 engr228-digital law-10027u fit5057 ve311 sle210 n1608 msim3101 badp2003 mth002 6012acc 072243a 3809ict amath 483 ifn556 cven4051 2024 comp9024 158.739-2024 comp 3023 ecs122a com63004 bms5021 comp1028 genc3004 phil2617
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图