The resolution of the structure clash is effected by decomposing the program P into two programs, PA and PB as shown below:

The data structures of the serial input file, A, the intermediate file, I, and the output file, X are shown below:

There is no structure clash between A and I, so the structure of PA can be constructed without difficulty; the same is true of I and X and PB. The intermediate file, I, contains the largest component common to both A and X--an idea analogous to the "greatest common divisor" of two integers.

The processing for the system diagram

can be accomplished in a number of ways:

(1) Batch processing: PA produces the serial data stream, I, which is then processed by program PB.

(2) Parallel processing: It would be more efficient if P2 processes each record of I as soon as it is created by PA instead of waiting until all of I has been produced. We can arrange PA and PB to be cooperating programs or coroutines. PA produces a record in a buffer and transfers control to PB which consumes (processes) the record and then transfers control back to PA again. The cooperation between PA and PB is depicted below:

Alternatively, PA and PB can be written as independent tasks under control of a multi-programming task supervisor which manages the alternating suspend and resume between the two tasks.

(3) Quasi-parallel processing: program inversion

Multi-programming is expensive in system resources. We can achieve a solution of a structure clash more cheaply: instead of running PA and PB in parallel, we can convert one so that it runs as a subroutine of the other. We call the conversion process, program inversion. The system diagram:

is rewritten as:

or as:

Program inversion is a purely mechanical transformation of the independent programs, PA and PB, into a main program and subroutine, where the subroutine has a single ENTRY point and stores its return address within itself so that it is resumable.

Consider the boundary clash example again:

We can convert the program PA into a procedure PAI, which has the characteristics of an input procedure for I. Successive calls to PAI will 'open I', 'read I' (iteratively), and 'close I'. PAI passes the next record to PB and notifies PB when an end of file has been reached. (Alternatively, we could convert PB into a procedure PBI, which has the characteristics of an output procedure for I.) PA and PAI are identical programs. PAI is a resumable or variable-state procedure, that is, it performs some operations, suspends its execution (passes control back to PB), and when called again, resumes at the point where it left off. PAI must keep track of its state, and does so with a state vector (or activation record) that holds the values of any variables together with a text pointer to the next instruction in its text to be executed.