# Chare Arrays: Particle Exercise Figure 1

## Random Migrating Particles

For this exercise, you will write code that simulates a set of particles moving randomly in a 2-dimensional space within a bounding box. The coordinates of the overall simulation box are between 0.0 and 100.0 along each dimension. The particles are divided among chares based on their coordinates. The chares should be organized in a 2-dimensional array of chares (using a chare array) of size k \times k. So, each chare owns a bounding box of its own with size 100.0/k. The particles in each chare can be stored as a vector.

Your program should generate n particles per chare during construction with a random (but valid, i.e. within the chare) position for particles. Your program should accept the number of particles per cell n, and k as command line parameters in that sequence.

Expected Output: Your program should calculate and print to screen the maximum and total number of particles every 10 iterations. Additionally, the simulation should not be delayed by this calculation (i.e. you should use reductions).

For testing your program, you can use 10000 (=n) particles per chare, simulated over 100 steps and a chare array of size 16 \times 16 (k=16). Experiment with different number of particles and chare array sizes.

Note: There might be multiple particles having the same x and y coordinates, especially if you increase the density of each cell. You do not need to handle this case separately; it is a valid case assumption.

• The pseudocode for the overall algorithm is:
• for(iteration=0; iteration<ITERATION; iteration++){
• For each of the particles that belong to my chare: change its x and y coordinate by a small random amount.
• Move all the particles that do not belong to a chare's bounding box to their correct homes. Since the movement is small, this will mean communication to the eight near neighbor chares. Some of these messages may contain no particles.
• if(iteration%10 == 0)
• Do reductions to calculate average and max number of particles
}
{"ft_lang_label":"__label__en","ft_lang_prob":0.86615705,"math_prob":0.9812455,"size":2040,"snap":"2020-45-2020-50","text_gpt3_token_len":451,"char_repetition_ratio":0.13998036,"word_repetition_ratio":0.0,"special_character_ratio":0.22058824,"punctuation_ratio":0.10769231,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97579545,"pos_list":[0,1,2],"im_url_duplicate_count":[null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-11-27T14:50:30Z\",\"WARC-Record-ID\":\"<urn:uuid:fb2c311f-fde9-49b8-bbf6-2aae08dce608>\",\"Content-Length\":\"8969\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:7ce1a545-37b5-4cdd-9c07-d2950debb4e7>\",\"WARC-Concurrent-To\":\"<urn:uuid:7507b2f3-5e94-436a-afd7-7ed0edc247b5>\",\"WARC-IP-Address\":\"128.174.239.11\",\"WARC-Target-URI\":\"http://charmplusplus.org/exercises/particle/\",\"WARC-Payload-Digest\":\"sha1:XZLQEONIN65KIIPXSOLGLQR6R52PDQ3U\",\"WARC-Block-Digest\":\"sha1:K4X64WKDIASUKDT7JWGAATPJ6BB3BUFX\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-50/CC-MAIN-2020-50_segments_1606141193221.49_warc_CC-MAIN-20201127131802-20201127161802-00278.warc.gz\"}"}