COMP 464 final practice answers

Practice problems for the final, with answers

MPI (5)

M1. This works with n = 10 and hangs with n = 10000000. Why?

Answer:

Small messages are usually buffered (eager), so MPI_Send returns. Large messages usually wait for the matching receive (rendezvous). Both ranks wait in MPI_Send. Neither reaches MPI_Recv. Deadlock.

Fixes: MPI_Sendrecv, non-blocking calls, or have one rank receive first.

M2. Ring shift with one MPI_Sendrecv.

Answer:

int right = (rank + 1) % size;
int left  = (rank - 1 + size) % size;
MPI_Sendrecv(&x, 1, MPI_DOUBLE, right, 0,
             &y, 1, MPI_DOUBLE, left,  0,
             MPI_COMM_WORLD, MPI_STATUS_IGNORE);

+ size keeps left from going negative on rank 0.

M3. Ring shift with non-blocking calls.

Answer:

MPI_Request reqs[2];
MPI_Irecv(&y, 1, MPI_DOUBLE, left,  0, MPI_COMM_WORLD, &reqs[0]);
MPI_Isend(&x, 1, MPI_DOUBLE, right, 0, MPI_COMM_WORLD, &reqs[1]);
/* other work: do not read y, do not change x */
MPI_Waitall(2, reqs, MPI_STATUSES_IGNORE);

M4. Every rank gets the largest t.

Answer:

double slowest;
MPI_Allreduce(&t, &slowest, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);

MPI_Reduce puts the result on the root only.

M5. Why MPI_Barrier before the first MPI_Wtime?

Answer:

Ranks arrive at different times. The barrier starts every clock together. Without it, each rank’s time includes its own head start or delay, and the times can’t be compared.

OpenMP (4)

O1. Pick a schedule.

Answer:

  1. static. Equal blocks are balanced and cost the least.
  2. static, 1, dynamic, or guided. Plain static gives the last thread the most work.
  3. dynamic or guided. Threads take the next chunk when they finish.

O2. Fix the race.

Answer:

long count = 0;
#pragma omp parallel for reduction(+:count)
for (long i = 0; i < N; i++)
    if (a[i] % 3 == 0) count++;

O3. First, last, split.

Answer:

Early iterations do the most work. Thread 0 finishes last. Thread 3 finishes first. Split is about 7 : 5 : 3 : 1.

O4. Read the numbers.

Answer:

  • 16.0 / 7.0 ≈ 2.3 CPUs busy, not 4.
  • Thread times match the 7 : 5 : 3 : 1 split. Load imbalance from static.
  • Thread 0 sets the runtime. Thread 3 is idle for 6 s.
  • Change to dynamic with a chunk size, guided, or static, 1.
  • Task-clock stays near 16 s. Elapsed drops to about 4 s.

Performance and observability (3)

P1. Metric, log, trace, or profile?

Answer:

  1. Metric
  2. Log
  3. Profile
  4. Trace

P2. Which is faster?

Answer:

A, about 4x (1.2 / 0.3). Same instructions, a quarter of the cycles. B is waiting on memory. Example: walking a row-major 2D array by column.

P3. One question each.

Answer:

  • User: Why is my program slow? Where are the hotspots? How much memory do I need?
  • System: Is this resource in use? Is a user misbehaving?
  • Admin: Why did this node die? What do we buy next?

Systems (4)

S1. Fastest to slowest.

Answer:

GPU HBM, DDR memory, node-local NVMe, home directory, parallel filesystem, archive.

Wiped at job end: GPU HBM, DDR memory, node-local NVMe.

S2. 1 PB at 100 Gb/s.

Answer:

1 PB = 10^15 bytes = 8 × 10^15 bits.

8 × 10^15 / 10^11 = 80,000 s ≈ 22 hours.

S3. VM, container, Docker, Apptainer.

Answer:

VM: the hypervisor isolates. Container: the host OS isolates. Docker usually needs root to start containers, and users can’t have root on a shared machine. Apptainer runs containers as the user, with the same permissions inside as outside. Admins own the setup.

S4. Four zones.

Answer:

  • Access: login nodes, data transfer nodes, web portals
  • Management: scheduler, provisioning, identity, logging, monitoring
  • HPC: compute nodes, high-speed network
  • Data storage: parallel filesystems, archives

Only access touches the outside network.

Fault tolerance (6)

F1. Fault, error, or failure. Transient, intermittent, or permanent.

Answer:

  1. Fault
  2. Error
  3. Failure
  4. Intermittent
  5. Permanent

F2. Make it restartable.

Answer:

long N = 1000000000, K = 10000000, start = 0;
double sum = 0.0;
FILE *fp = fopen("state.txt", "r");
if (fp) {
    fscanf(fp, "%ld %lf", &start, &sum);
    fclose(fp);
}
for (long i = start; i < N; i++) {
    sum += work(i);
    if ((i + 1) % K == 0) {
        FILE *t = fopen("state.tmp", "w");
        fprintf(t, "%ld %.17g\n", i + 1, sum);
        fclose(t);
        rename("state.tmp", "state.txt");
    }
}
printf("sum = %f\n", sum);

Save two values: the next iteration (i + 1) and the sum. %.17g writes every digit of the double, so a restarted run matches an uninterrupted one.

F3. Why a temporary file?

Answer:

A kill during the write leaves a partial state.txt. With a temporary file, the old state.txt stays intact until rename replaces it.

F4. Two reasons.

Answer:

  • Extra copies multiply the cost of every job.
  • HPC jobs are tightly coupled. One dead rank stalls the rest, so a replica doesn’t keep the job running.
  • Checkpoint/restart works with any application.

F5. One line each.

Answer:

  • SCR: multi-level checkpointing (LLNL). Frequent checkpoints to node-local storage, occasional ones to the parallel filesystem.
  • VeloC: asynchronous checkpointing (Argonne, LLNL). The app blocks only for the fastest level; a background process copies the rest.
  • CRIU: system-level checkpoint/restore of a whole process. No code changes.
  • ULFM: proposed MPI extension. A failed rank returns an error instead of ending the job; survivors revoke and shrink the communicator.
  • ABFT: checksums in the algorithm find and fix bad values without a checkpoint.

F6. DRAIN.

Answer:

No new jobs go to that node. An admin or a health check took it out of service. Check whether the job died from the machine (NODE_FAIL) or from your code (errors in your output). If it was the machine, resubmit from your last checkpoint.