Increase arithmetic after one element load
For each float, load a value, apply x=0.5x+0.25 q times and store it once. Compare q equal to one and sixteen while retaining the same element count. Read the Roofline guide first. This changes the workload to study nominal work per transfer; adding arithmetic is not itself an optimization completing an unchanged application sooner. Separate a reported FLOP rate from useful application progress.
Inputs are 0.5, which remains 0.5 after every update and provides an exact output check. A constant expected result does not prove the computation survives compilation, so inspect the binary as well. The kernel reads through a pointer and receives q as an argument. Record the implementation it actually executes. Allowing fusion or reassociation in another build changes operation counting or numerical assumptions and must be labeled, rather than treated as the same experimental condition.
Calculate work and nominal bytes first
Count one multiplication and one addition per update, giving 2q operations per element. Four bytes read and four written give eight nominal bytes, so intensity is q/4 FLOP/B: 0.25 at q=1 and four at q=16. For n elements the totals are 2qn operations and 8n useful read/write bytes. These are specification-derived quantities, not memory-controller observations. Write allocation and reuse can change actual boundary traffic.
Use -ffp-contract=off in this build to make fusion an explicit controlled condition. Instruction count and FLOP count remain different concepts; a fused multiply-add can still be counted as two FLOP under a stated convention. Consistent conventions matter more than equating operations with instructions. Raising q also lengthens an element's dependency chain. Do not claim that only intensity changes while every other execution property remains identical. That chain can limit throughput below an illustrative arithmetic ceiling.
Run two sizes and two arithmetic counts
Save intensity.c and compile with gcc -O2 -std=c11 -fno-ipa-pure-const -ffp-contract=off intensity.c -o intensity, then run it. The allocations are 32 KiB and 64 MiB. Each q value receives nine samples per size. Resetting input, validating every output, checksum formation and printing are outside timing. CSV identifies length, q, repetition, nanoseconds and checksum. The recorded compiler is GCC 13.3.
Reset writes affect the state preceding the timed call, especially for the larger array. Neither case claims to start with an empty hierarchy. Rotate which q runs first and preserve all samples; that reduces one ordering bias without eliminating environmental variation. Before adding larger cases, estimate both allocation and the q-dependent arithmetic workload. A buffer-size change alone can greatly increase total execution time when the inner update repeats sixteen times per element.
#define _POSIX_C_SOURCE 200809L
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
static volatile uint64_t sink;
static uint64_t ns(void) { struct timespec t; assert(!clock_gettime(CLOCK_MONOTONIC,&t)); return (uint64_t)t.tv_sec*1000000000u+t.tv_nsec; }
__attribute__((noinline)) static void kernel(float *a,size_t n,int rounds) {
for(size_t i=0;i<n;i++){float x=a[i];for(int j=0;j<rounds;j++)x=x*0.5f+0.25f;a[i]=x;}
}
int main(void) {
size_t sizes[]={8192,16777216};int rounds[]={1,16};
for(int z=0;z<2;z++){size_t n=sizes[z];float *a=malloc(n*sizeof(*a));assert(a);
for(int r=0;r<9;r++)for(int k=0;k<2;k++){int q=rounds[(r+k)%2];for(size_t i=0;i<n;i++)a[i]=0.5f;
uint64_t start=ns();kernel(a,n,q);uint64_t elapsed=ns()-start;uint64_t sum=0;
for(size_t i=0;i<n;i++){assert(a[i]==0.5f);sum+=(uint64_t)(a[i]*2);}sink=sum;printf("%zu,%d,%d,%llu,%llu\n",n,q,r,(unsigned long long)elapsed,(unsigned long long)sum);
}free(a);
}return 0;
}
Verify computation as well as its final value
Every output should be 0.5 and the checksum n for both q values. Also inspect the called kernel in objdump output: locate its load, repeated multiplication and addition, inner control flow and final store. Follow any specialized symbol suffix. Missing the original symbol name does not establish missing work; conversely, a correct constant result does not by itself prove that repeated arithmetic remains in the timed binary.
Additional inputs need an appropriate reference, such as higher precision or the same required operation order. The fixed-point input here does not assess accuracy for every float. New cases involving tiny values or NaNs also need a matching comparison contract. A NaN does not normally compare equal to itself, so an equality assertion failure is not automatically a compiler defect. Establish input, operation semantics and output judgment together before interpreting a timing change.
Do not rename nominal throughput as measured bandwidth
Divide 2qn by elapsed seconds for a FLOP rate under the declared counting convention. Dividing 8n by time gives nominal useful-byte throughput, not measured DRAM bandwidth. Small repeated inputs can be supplied by caches, while even large inputs need separate traffic observations. The virtualized evidence acquires no PMU events, so nominal intensity and measured DRAM intensity remain separate, with the latter unmeasured.
A higher reported FLOP rate at q=16 does not establish faster completion of unchanged work; arithmetic work increased sixteenfold. Present total time, time per element and nominal operation rate together. The guide's 200 GFLOP/s and 50 GB/s are teaching assumptions, not calibrated ceilings for these samples. Hardware-specific follow-up needs matching precision, threads, placement, ISA and measured ceilings. Preserving those boundaries makes the result interpretable instead of merely more numerically elaborate.
Do not equate FLOP counts with instruction counts
At q=16 the declared work is 32 FLOP per element, not a promise of 32 machine instructions. Loads, stores and control flow also occupy instructions, and transformations can process several elements together. Use the stated arithmetic convention in the operation-rate numerator and keep disassembly counts or retired-instruction counters in separate fields. Comparing those quantities can be useful, but assigning them the same unit creates a false explanation. The source contract, resulting binary and hardware events answer related but different questions.
Solve the operation-count exercise
At q=8 and n=1000, the nominal totals are 16,000 FLOP, 8,000 bytes and two FLOP/B. Doubling q changes arithmetic without changing the number of array elements. Setting q to zero instead returns each original value unchanged and may allow the compiler to remove redundant accesses. It is therefore not automatically a valid baseline for the original transfer pattern; inspect what remains in the binary.
To evaluate optimization of equal useful work, fix required operations, input and output accuracy, then compare complete duration. Raising intensity alone is insufficient. At completion retain the labeled CSV, code, binary and diagnostics or remove them. Each allocation is freed after its size's observations, and no external connection or background service is used. Continue to the warmup-method experiment for a closer examination of first and repeated observations.