Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Shared
- my_rank = Get_rank();
- m = 0
- if (my_rank == 0) { // core 0
- while (flag < p - 1); // Busy-wait until all other cores finish sending
- PI = 4 * m / n // Computate PI
- printf("PI: %d\n ", PI) // print PI
- } else {
- // theoretically n = 100, p = 8
- // my_rank 1 (for x = 0; x < 15; x++)
- // my_rank 2 (for x = 15; x < 30; x++)
- // etc...
- for (int x = (ceil(n/p) * (my_rank - 1)); x < (ceil(n/p) * (my_rank)); x++) { // for each point in this process
- if x == n { break; } // break when last core finishes x
- new_point = generate_point() // randomly generate point in the square
- is_in_circle = check_if_in_circle(new_point) // check if point is in circle
- if (is_in_circle) { // if is in circle
- Lock(&add_m_lock) // lock mutex
- m += 1 // add to m
- Unlock(&add_m_lock) // unlock mutex
- }
- flag++ // increment flag
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement