Continuous Internal Evaluation (CIE) Questions
-
Write an OpenMP program to count how many prime numbers exist between 1 and n using
parallel forwith dynamic scheduling. Compare the result with a serial version.Sample Input:
Expected Output:n = 20Serial Count of primes = 8 Parallel Count of primes = 8 Execution time (serial): 0.00123 seconds Execution time (parallel): 0.00045 seconds -
Write an MPI program where process 0 sends an integer value to process 1, and process 1 multiplies it by 2 and prints the result.
Sample Input:
Expected Output:Process 0 sends integer: 5Process 1 received 5 Process 1 multiplied value = 10 -
Write an MPI program where process 0 waits to receive a message from process 1, and process 1 waits to receive from process 0 (causing deadlock). Then modify the program to avoid deadlock by letting one process send first and the other receive first.
Case 1 (Deadlock):
Case 2 (Fixed):(Program hangs, no output)Process 0 received message: Hello from Process 1 Process 1 received message: Hello from Process 0 -
Write an MPI program where process 0 reads an array of 5 integers from the user and broadcasts it to all processes using
MPI_Bcast. Each process should print the array it received.Sample Input:
Expected Output (for 4 processes):Enter 5 integers: 1 2 3 4 5Process 0 received array: 1 2 3 4 5 Process 1 received array: 1 2 3 4 5 Process 2 received array: 1 2 3 4 5 Process 3 received array: 1 2 3 4 5 -
Write an MPI program where process 0 has an array of numbers, scatters them to all processes, and gathers back their squared values.
Sample Input (array at process 0 with 4 processes):
Expected Output:Array: [1, 2, 3, 4]Process 0 got 1 → squared = 1 Process 1 got 2 → squared = 4 Process 2 got 3 → squared = 9 Process 3 got 4 → squared = 16 Gathered result at Process 0: [1, 4, 9, 16] -
Write an MPI program where each process has its rank as a number. Use
MPI_Reduceto find the sum of all ranks at process 0, andMPI_Allreduceto share the sum with all processes.Sample Input (4 processes):
Expected Output:Process ranks: 0, 1, 2, 3MPI_Reduce result at Process 0: Sum of ranks = 6 MPI_Allreduce result at all processes: Sum of ranks = 6