Self-Assessment Quiz: Coarrays
Twenty questions to confirm the coarray model landed before you move on to OpenMP. Aim for 16 or more. Work the "what does it print?" items by predicting the value on the stated image count first; the answer key and a topic map are at the end.
Question 1
An image, in coarray Fortran, is best described as: - A. A thread sharing one address space with the others - B. One of several concurrent instances of the program, each with its own private copy of every variable - C. A GPU kernel - D. A section of a single array
Question 2
this_image() returns _ and num_images() returns _.
- A. the total count; the calling image's number
- B. the calling image's number (1..N); the total number of images N
- C. 0; 1
- D. the number of CPU cores; the number of threads
Question 3
Which declaration makes a a coarray?
- A. real :: a(100)
- B. real :: a[*]
- C. real, parallel :: a
- D. real :: a // *
Question 4
In real :: a(100)[*], the (100) is the _ and the [*] is the _.
- A. coshape; local shape
- B. local shape (per image); coshape (over images)
- C. lower bound; upper bound
- D. corank; rank
Question 5
For a coarray a, the expression a[q] means:
- A. the q-th element of the local a
- B. image q's copy of a
- C. a raised to the power q
- D. a syntax error unless q equals this_image()
Question 6
An unbracketed reference to a coarray, a, refers to:
- A. image 1's copy always
- B. the calling image's own copy (i.e. a[this_image()])
- C. all images' copies summed
- D. an undefined value
Question 7
True or false, with justification: writing a = a + 1 on every image increments a single shared a a total
of num_images() times.
Question 8
The statement sync all guarantees that:
- A. all images print in order
- B. no image continues past it until every image has reached it, so writes before it are safe to read after
- C. the program runs on all available cores
- D. coarrays are automatically summed
Question 9
Why does a "write a coarray, then read it on another image" sequence need a synchronization between the two?
- A. To make the program run faster
- B. Otherwise the read and write fall in unordered segments and the result is undefined (a race)
- C. Because sync all allocates the coarray
- D. It does not — coarrays are always safe
Question 10
sync images([2]) executed on image 1 does what, compared to sync all?
- A. Exactly the same as sync all
- B. Synchronizes image 1 only with image 2 (pairwise), leaving other images free
- C. Terminates image 2
- D. Broadcasts to all images
Question 11
The critical construct is used to:
- A. mark the most important code
- B. ensure only one image at a time executes the enclosed block (mutual exclusion)
- C. speed up a loop
- D. broadcast a value
Question 12
After total = this_image(); call co_sum(total) on 4 images, every image's total is:
- A. its own image number
- B. 10 (= 1+2+3+4)
- C. 4
- D. undefined
Question 13
call co_broadcast(x, source_image=2) does what?
- A. Sums x across images
- B. Copies image 2's value of x to every image's x
- C. Sends x only to image 3
- D. Deletes x on image 2
Question 14
A collective subroutine such as co_sum must be called by:
- A. image 1 only
- B. every image (with matching arguments)
- C. any single image
- D. exactly two images
Question 15
Which of these is the honest status of teams (form team/change team) in current gfortran?
- A. Fully supported and fast
- B. Standard (Fortran 2018) but incompletely supported by gfortran; verify or use ifx
- C. Removed from the language
- D. Only available in Python
Question 16
To test the correctness of coarray logic on a laptop with only gfortran, you compile with:
- A. -fopenmp
- B. -fcoarray=single (runs as one image; syncs become no-ops)
- C. -llapack
- D. nothing special; it just works in parallel
Question 17
To run a gfortran coarray program on multiple images you need:
- A. nothing extra — gfortran does it alone
- B. the external OpenCoarrays library, via caf to compile and cafrun -n N to launch
- C. a GPU
- D. to rewrite it in MPI
Question 18
The solver's plate is decomposed along columns rather than rows because:
- A. rows do not exist in Fortran
- B. a column u(:,j) is contiguous in column-major memory, so a halo is one contiguous, efficient transfer
- C. columns are always shorter
- D. it makes no difference
Question 19
In the coarray heat solver, the two sync all statements inside each time step are there to:
- A. speed up the stencil
- B. order the halo reads against neighbours' commits, so no image reads a strip another is still updating
- C. print the field
- D. allocate the coarray each step
Question 20
What does this print on 3 images (image 1 does the printing)?
integer :: v[*], q
v = this_image() * this_image()
sync all
if (this_image() == 1) then
do q = 1, num_images(); print '(i0)', v[q]; end do
end if
- A.
1then2then3 - B.
1then4then9 - C.
3nine times - D. undefined (missing sync)
Answer Key
| Q | Ans | Why |
|---|---|---|
| 1 | B | An image is a concurrent instance with its own private data (distributed-memory model). |
| 2 | B | this_image() = caller's number 1..N; num_images() = N. |
| 3 | B | The codimension [*] makes it a coarray. |
| 4 | B | ( ) is the per-image local shape; [ ] is the coshape over images. |
| 5 | B | a[q] is image q's copy — a coindexed reference. |
| 6 | B | Unbracketed = the local copy, i.e. a[this_image()]. |
| 7 | False | Each image has its own a; you get N separate as each incremented once, not one shared a incremented N times. |
| 8 | B | sync all is a barrier; writes before it are safe to read after it (ordered segments). |
| 9 | B | Without synchronization the accesses are in unordered segments — undefined, a race. |
| 10 | B | sync images is pairwise/selective; other images keep running. |
| 11 | B | critical gives mutual exclusion — one image at a time. |
| 12 | B | co_sum combines across images; 1+2+3+4 = 10 on every image. |
| 13 | B | co_broadcast copies the source image's value to all. |
| 14 | B | A collective must be called by every image with matching arguments. |
| 15 | B | Teams are standard but weakly supported by gfortran today; prefer ifx or verify. |
| 16 | B | -fcoarray=single builds a correct one-image program for testing. |
| 17 | B | Multi-image gfortran needs OpenCoarrays (caf/cafrun). |
| 18 | B | Column halos are contiguous in column-major layout — one efficient message. |
| 19 | B | The two barriers order halo reads against neighbours' commits (no race). |
| 20 | B | v = i*i gives 1, 4, 9; the sync all makes the reads safe; image 1 prints in order. |
Topics to review by question
- Q1–2, Q7 → §32.1 (images, SPMD, this_image/num_images, private copies).
- Q3–6, Q20 → §32.1–32.2 (declaring a coarray, coindexed access, local vs remote).
- Q8–11, Q19 → §32.3 (sync all, sync images, critical, segments, the solver's barriers).
- Q12–15 → §32.4 (co_sum/co_max/co_broadcast, who must call, teams and their support).
- Q16–17 → §32.5 (building: -fcoarray=single vs OpenCoarrays caf/cafrun).
- Q18 → §32.2/Project Checkpoint (column-major halos).
Scored below 16? The two ideas most worth rereading are the difference between a local reference a and a
coindexed one a[q] (Q5–6, 7, 20), and why every remote access must be ordered by a synchronization
(Q8–9, 19) — together they are the whole correctness story of the chapter.