feat(docs): add the documentation site

- Astro and Starlight site in docs/ for
  https://fairrootgroup.github.io/FairMQ/
- 64 pages in eight groups: start, concepts, guides, shared memory,
  examples, tools, reference and project
- API reference and source browser from the Doxygen XML of fairmq/
- Code samples are snippets of the repository files; the build fails
  when a snippet does not match
- Option tables take the names, types and defaults from the code
- Interactive diagrams: state machine, zero-copy transfer, region
  acknowledgements, session objects, topology and channel anatomy
- The 404 page sends the URLs of the Doxygen site to the new pages
- scripts/check-pages.mjs checks pages, snippets and links without a
  build; scripts/check-links.mjs checks all links in dist/

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-11-05 00:17:41 +00:00
committed by Dennis Klein
parent 866f39f54e
commit 992db82b91
120 changed files with 27931 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
---
// A small button that copies a text to the clipboard.
interface Props {
text: string;
label?: string;
}
const { text, label = 'Copy' } = Astro.props;
---
<button type="button" class="fmq-copy" data-copy={text} aria-label={label} title={label}>Copy</button>
<script>
document.addEventListener('click', async (e) => {
const btn = (e.target as HTMLElement).closest<HTMLButtonElement>('button.fmq-copy');
if (!btn) return;
const text = btn.dataset.copy ?? '';
const done = (msg: string) => {
btn.textContent = msg;
setTimeout(() => (btn.textContent = 'Copy'), 1400);
};
try {
await navigator.clipboard.writeText(text);
done('Copied');
} catch {
done('Not copied');
}
});
</script>
<style>
.fmq-copy {
font: 500 0.75rem/1 var(--fmq-font-body);
border: 1px solid var(--fmq-rule-strong);
background: var(--fmq-paper);
color: var(--fmq-ink-2);
border-radius: 3px;
padding: 0.3rem 0.5rem;
cursor: pointer;
}
.fmq-copy:hover {
border-color: var(--fmq-ink-3);
color: var(--fmq-ink);
}
</style>

View File

@@ -0,0 +1,21 @@
---
// The FairMQ mark: two devices and a message on the channel between them.
interface Props {
size?: number;
}
const { size = 28 } = Astro.props;
---
<svg class="fmq-glyph" width={size} height={Math.round((size * 18) / 30)} viewBox="0 0 30 18" aria-hidden="true">
<rect x="1" y="4" width="10" height="10" fill="none" stroke="currentColor" stroke-width="1.6"></rect>
<rect x="19" y="4" width="10" height="10" fill="none" stroke="currentColor" stroke-width="1.6"></rect>
<line x1="11" y1="9" x2="19" y2="9" stroke="currentColor" stroke-width="1.6"></line>
<rect x="13" y="7" width="4" height="4" fill="var(--fmq-saffron)" stroke="var(--fmq-bar)" stroke-width="0.6"></rect>
</svg>
<style>
.fmq-glyph {
flex: none;
color: var(--fmq-ink);
}
</style>

View File

@@ -0,0 +1,263 @@
---
// Table of command-line options, read from the C++ code at build time.
//
// <OptionsTable /> all options of a device made with runDevice.h
// <OptionsTable groups={['Shared memory']} /> only some groups, without the filter
// <OptionsTable file="fairmq/shmem/runMonitor.cxx" texts={...} /> the options of a tool
import { paths } from 'virtual:fairmq/data';
import { deviceOptions, readOptions } from '../../scripts/options.mjs';
import { deviceOptionTexts } from '../data/option-texts.mjs';
interface Props {
file?: string;
groups?: string[];
texts?: Record<string, string>;
filter?: boolean;
id?: string;
}
const { file, groups, texts, filter, id = 'opt' } = Astro.props;
const base = import.meta.env.BASE_URL.replace(/\/$/, '');
let options = file
? readOptions(paths.repoRoot, [{ file, source: file.split('/').pop(), group: 'Options' }])
: deviceOptions(paths.repoRoot);
const curated = texts ?? (file ? {} : deviceOptionTexts);
for (const key of Object.keys(curated)) {
if (!options.some((o: any) => o.name === key)) throw new Error(`OptionsTable: no option --${key} in the code (${file ?? 'device options'})`);
}
if (groups) options = options.filter((o: any) => groups.includes(o.group));
const order = ['Device', 'Shared memory', 'Control', 'Logging', 'Plugins', 'General', 'Options'];
const allGroups = [...new Set(options.map((o: any) => o.group))].sort((a: any, b: any) => order.indexOf(a) - order.indexOf(b));
const showFilter = filter ?? (!groups && options.length > 12);
const sorted = [...options].sort((a: any, b: any) => order.indexOf(a.group) - order.indexOf(b.group));
const fmt = (v: string | undefined) => (v === undefined ? undefined : v === '' ? '""' : v);
---
<div class="fmq-opts not-content" data-opts>
{
showFilter && (
<div class="fmq-opts-bar" role="group" aria-label="Filter options">
<input type="search" placeholder="Filter, for example shm or timeout" aria-label="Filter options" />
<div class="fmq-opts-groups">
<button type="button" data-g="" aria-pressed="true">
All
</button>
{allGroups.map((g) => (
<button type="button" data-g={g} aria-pressed="false">
{g}
</button>
))}
</div>
<p class="fmq-opts-count" aria-live="polite">
{options.length} options
</p>
</div>
)
}
<div class="fmq-opts-scroll">
<table>
<thead>
<tr>
<th scope="col">Option</th>
<th scope="col">Default</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
{
sorted.map((o: any) => (
<tr id={`${id}-${o.name}`} data-g={o.group} data-q={`${o.name} ${o.short} ${o.description} ${curated[o.name] ?? ''}`.toLowerCase()}>
<td class="o-name">
<a href={`#${id}-${o.name}`}>
<code>
{o.short && `-${o.short}, `}--{o.name}
</code>
</a>
<span class="o-type">{o.flag ? 'flag' : o.type}{o.multitoken ? ', several values' : ''}</span>
</td>
<td class="o-def">
{fmt(o.default) !== undefined ? <code>{fmt(o.default)}</code> : o.implicit !== undefined ? <span class="o-none">no value: {o.implicit}</span> : <span class="o-none">—</span>}
</td>
<td class="o-desc">
<Fragment set:html={curated[o.name] ?? o.description.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\n/g, '<br>')} />
<a class="o-src" href={`${base}/source/${o.file}/#L${o.line}`} title={`Defined in ${o.file}:${o.line}`}>
{o.source}
</a>
</td>
</tr>
))
}
<tr class="o-empty" hidden>
<td colspan="3">No option matches. Clear the filter or choose All.</td>
</tr>
</tbody>
</table>
</div>
</div>
<script>
for (const root of document.querySelectorAll<HTMLElement>('[data-opts]')) {
const input = root.querySelector<HTMLInputElement>('input[type=search]');
if (!input) continue;
const buttons = [...root.querySelectorAll<HTMLButtonElement>('button[data-g]')];
const rows = [...root.querySelectorAll<HTMLTableRowElement>('tbody tr[data-g]')];
const empty = root.querySelector<HTMLTableRowElement>('tr.o-empty')!;
const count = root.querySelector('.fmq-opts-count')!;
let group = '';
const apply = () => {
const q = input.value.trim().toLowerCase();
let n = 0;
for (const r of rows) {
const ok = (!group || r.dataset.g === group) && (!q || (r.dataset.q ?? '').includes(q));
r.hidden = !ok;
if (ok) n++;
}
empty.hidden = n > 0;
count.textContent = n === rows.length ? `${rows.length} options` : `${n} of ${rows.length} options`;
};
input.addEventListener('input', apply);
for (const b of buttons)
b.addEventListener('click', () => {
group = b.dataset.g ?? '';
for (const o of buttons) o.setAttribute('aria-pressed', String(o === b));
apply();
});
}
</script>
<style>
.fmq-opts {
margin-block: 1.25rem;
}
.fmq-opts-bar {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
align-items: center;
margin-bottom: 0.5rem;
}
.fmq-opts-bar input {
flex: 1 1 16rem;
max-width: 22rem;
font: 400 0.9375rem var(--fmq-font-body);
color: var(--fmq-ink);
background: var(--fmq-paper-2);
border: 1px solid var(--fmq-rule-strong);
border-radius: 4px;
padding: 0.4rem 0.6rem;
}
.fmq-opts-groups {
display: flex;
flex-wrap: wrap;
gap: 0.35rem;
}
.fmq-opts-groups button {
font: 500 0.8125rem/1 var(--fmq-font-body);
border: 1px solid var(--fmq-rule-strong);
border-radius: 3px;
background: var(--fmq-paper);
color: var(--fmq-ink-2);
padding: 0.4rem 0.6rem;
cursor: pointer;
}
.fmq-opts-groups button:hover {
border-color: var(--fmq-ink-3);
color: var(--fmq-ink);
}
.fmq-opts-groups button[aria-pressed='true'] {
background: var(--fmq-saffron-tint);
border-color: var(--fmq-bar);
color: var(--fmq-ink);
}
.fmq-opts-count {
flex-basis: 100%;
margin: 0;
font-size: 0.8125rem;
color: var(--fmq-ink-3);
}
.fmq-opts-scroll {
overflow-x: auto;
border-top: 1px solid var(--fmq-rule-strong);
}
table {
width: 100%;
border-collapse: collapse;
font-size: 0.9rem;
min-width: 40rem;
}
th {
text-align: start;
font: 600 0.7rem/1.2 var(--fmq-font-body);
font-stretch: 88%;
letter-spacing: 0.1em;
text-transform: uppercase;
color: var(--fmq-ink-3);
padding: 0.55rem 0.6rem;
border-bottom: 1px solid var(--fmq-rule-strong);
}
td {
padding: 0.55rem 0.6rem;
border-bottom: 1px solid var(--fmq-rule);
vertical-align: top;
line-height: 1.5;
}
tr:target {
background: var(--fmq-saffron-tint);
}
tr[id] {
scroll-margin-top: 6rem;
}
code {
font-family: var(--fmq-font-mono);
font-size: 0.82rem;
}
.o-name a {
color: var(--fmq-ink);
text-decoration: none;
font-weight: 600;
white-space: nowrap;
}
.o-name a:hover {
color: var(--fmq-link);
}
.o-type {
display: block;
font: 400 0.72rem var(--fmq-font-mono);
color: var(--fmq-ink-3);
margin-top: 0.15rem;
}
.o-def code {
white-space: nowrap;
background: var(--fmq-paper-3);
border: 1px solid var(--fmq-rule);
border-radius: 3px;
padding: 0.05em 0.35em;
}
.o-none {
color: var(--fmq-ink-3);
font-size: 0.8125rem;
}
.o-desc :global(code) {
background: var(--fmq-paper-3);
border: 1px solid var(--fmq-rule);
border-radius: 3px;
padding: 0.05em 0.3em;
}
.o-src {
margin-inline-start: 0.4rem;
font: 500 0.7rem var(--fmq-font-mono);
color: var(--fmq-ink-3);
text-decoration: none;
white-space: nowrap;
}
.o-src:hover {
color: var(--fmq-link);
}
.o-empty td {
text-align: center;
color: var(--fmq-ink-3);
padding: 1.25rem;
}
tr[hidden] {
display: none;
}
</style>

View File

@@ -0,0 +1,68 @@
---
// Shows code from a file of the repository, so that samples are code that CI compiles.
//
// <Snippet file="examples/1-1/sampler.cxx" /> whole file, without the license header
// <Snippet file="examples/1-1/sampler.cxx" region="run" /> lines between the markers //! [run]
// <Snippet file="examples/1-1/sampler.cxx" lines="20-34" /> a line range (1-based, inclusive)
// <Snippet file="examples/1-1/sampler.cxx" start="bool ConditionalRun()" />
// from the first line that contains the text to the line that closes its braces
// <Snippet file="examples/1-1/sampler.cxx" start="void addCustomOptions" end="^}" />
// from the start line to the next line that matches end (text, or /regex/ like "^}")
//
// The build fails if the file, the region, the lines or the start text do not exist.
import { Code } from '@astrojs/starlight/components';
import path from 'node:path';
import { paths, build } from 'virtual:fairmq/data';
import { extractSnippet } from '../../scripts/snippet.mjs';
interface Props {
file: string;
region?: string;
lines?: string;
start?: string;
end?: string;
lang?: string;
title?: string;
mark?: string | string[];
link?: boolean;
}
const { file, region, lines, start, end, lang, title, mark, link = true } = Astro.props;
const { code, first, last: lastLine } = extractSnippet(paths.repoRoot, { file, region, lines, start, end });
const ext = path.extname(file).slice(1);
const language =
lang ?? ({ cxx: 'cpp', cpp: 'cpp', h: 'cpp', hpp: 'cpp', sh: 'sh', json: 'json', cmake: 'cmake', txt: 'cmake', py: 'python', in: 'sh' } as Record<string, string>)[ext] ?? 'text';
const base = import.meta.env.BASE_URL.replace(/\/$/, '');
const sourceLink = /^fairmq\/.*\.(h|cxx)$/.test(file) ? `${base}/source/${file}/#L${first}-L${lastLine}` : `${build.repo}/blob/${build.commit}/${file}#L${first}-L${lastLine}`;
---
<div class="fmq-snippet">
<Code code={code} lang={language} title={title ?? file} mark={mark} />
{
link && (
<a class="fmq-snippet-src" href={sourceLink}>
{file}:{first}–{lastLine}
</a>
)
}
</div>
<style>
.fmq-snippet {
margin-block: 1rem;
}
.fmq-snippet :global(.expressive-code) {
margin-block: 0 !important;
}
.fmq-snippet-src {
display: block;
text-align: end;
margin-top: 0.3rem;
font: 500 0.72rem var(--fmq-font-mono);
color: var(--fmq-ink-3);
text-decoration: none;
}
.fmq-snippet-src:hover {
color: var(--fmq-link);
}
</style>

View File

@@ -0,0 +1,109 @@
---
// One member of a class or namespace: signature, comment, parameters, source line.
import { base } from '../../lib/model.mjs';
import { family } from '../../lib/families.mjs';
interface Props {
m: any;
owner?: any;
}
const { m, owner } = Astro.props;
const badges: { text: string; cls?: string }[] = [];
if (m.template) badges.push({ text: 'template' });
if (m.static && m.kind === 'function') badges.push({ text: 'static' });
if (m.virt === 'pure-virtual') badges.push({ text: 'pure virtual' });
else if (m.virt === 'virtual') badges.push({ text: 'virtual' });
if (m.prot === 'protected') badges.push({ text: 'protected' });
if (m.deprecated) badges.push({ text: 'deprecated', cls: 'deprecated' });
if (m.since) badges.push({ text: `since ${m.since}`, cls: 'since' });
const src = `${base}/source/${m.file}/#L${m.line}`;
const fileName = m.file.split('/').pop();
const fam = owner ? family(m, owner) : '';
const Heading = m.overload > 1 ? 'p' : 'h3';
const hasDetails = m.params.length || m.tparams.length || m.returns || m.retvals.length || m.throws.length;
---
<article class="mem" data-family={fam} data-name={m.name.toLowerCase()}>
<div class="mem-h">
<Heading id={m.anchor} class="mem-name"><a href={`#${m.anchor}`}>{m.name}</a></Heading>
{badges.map((b) => <span class:list={['fmq-badge', b.cls]}>{b.text}</span>)}
<a class="mem-src" href={src}>{fileName}:{m.line}</a>
</div>
<pre class="mem-sig"><code set:html={m.sigHtml} /></pre>
{m.deprecated && <div class="doc-aside caution"><b>Deprecated</b><Fragment set:html={m.deprecated} /></div>}
{m.brief && <p class="mem-brief" set:html={m.brief} />}
{m.detail && <div class="mem-detail" set:html={m.detail} />}
{
hasDetails ? (
<dl class="mem-params">
{m.tparams.map((p: any) => (
<>
<dt>
<code>{p.name}</code> <span class="mem-pk">template parameter</span>
</dt>
<dd set:html={p.html || '—'} />
</>
))}
{m.params.map((p: any) => (
<>
<dt>
<code>{p.name}</code>
{p.dir && <span class="mem-pk">{p.dir}</span>}
</dt>
<dd set:html={p.html || '—'} />
</>
))}
{m.returns && (
<>
<dt class="mem-ret">Returns</dt>
<dd set:html={m.returns} />
</>
)}
{m.retvals.map((p: any) => (
<>
<dt>
<code>{p.name}</code> <span class="mem-pk">return value</span>
</dt>
<dd set:html={p.html} />
</>
))}
{m.throws.map((p: any) => (
<>
<dt>
<code>{p.name}</code> <span class="mem-pk">throws</span>
</dt>
<dd set:html={p.html} />
</>
))}
</dl>
) : null
}
{
m.values && m.values.length > 0 && (
<div class="doc-table">
<table class="enum-values">
<thead>
<tr>
<th>Enumerator</th>
<th>Value</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{m.values.map((v: any) => (
<tr id={`${m.anchor}-${v.anchor}`}>
<td>
<code>{v.name}</code>
</td>
<td>{v.init ? <code>{v.init}</code> : <span class="muted">—</span>}</td>
<td set:html={v.html || '<span class="muted">—</span>'} />
</tr>
))}
</tbody>
</table>
</div>
)
}
{m.see.length > 0 && <p class="mem-see">See also: <Fragment set:html={m.see.join(', ')} /></p>}
{!m.documented && <p class="mem-none">No comment in the header yet.</p>}
</article>

View File

@@ -0,0 +1,124 @@
---
// A device with two channels. A channel is a vector of sub-channels; each sub-channel owns one socket.
// Facts: fairmq/Device.h (fChannels: name → std::vector<Channel>, GetChannel(name, index)),
// fairmq/Channel.h (type, method, address, transport).
const subs = [
{ x: 28, ch: 'data-in', i: 0, type: 'pull', method: 'connect', addr: 'tcp://sampler:5555', side: 'in' },
{ x: 336, ch: 'data-out', i: 0, type: 'push', method: 'bind', addr: 'tcp://*:5556', side: 'out' },
{ x: 486, ch: 'data-out', i: 1, type: 'push', method: 'bind', addr: 'tcp://*:5557', side: 'out' },
];
---
<figure class="fmq-chan not-content">
<svg viewBox="0 0 660 250" role="img" aria-label="A device with the channel data-in (one sub-channel) and the channel data-out (two sub-channels). Each sub-channel owns one socket.">
<rect class="dev" x="10" y="10" width="640" height="190" rx="3"></rect>
<text class="dev-l" x="24" y="32">device · --id processor1</text>
<rect class="ch" x="20" y="44" width="162" height="146" rx="2"></rect>
<text class="ch-l" x="30" y="62">channel "data-in"</text>
<rect class="ch" x="328" y="44" width="312" height="146" rx="2"></rect>
<text class="ch-l" x="338" y="62">channel "data-out"</text>
{
subs.map((s) => (
<g>
<rect class="sub" x={s.x} y="72" width="146" height="108" rx="2" />
<text class="sub-l" x={s.x + 10} y="90">
sub-channel [{s.i}]
</text>
<text class="kv" x={s.x + 10} y="112">
<tspan class="k">type</tspan> {s.type}
</text>
<text class="kv" x={s.x + 10} y="130">
<tspan class="k">method</tspan> {s.method}
</text>
<text class="kv addr" x={s.x + 10} y="148">
{s.addr}
</text>
<rect class="sock" x={s.x + 10} y="158" width="10" height="10" />
<text class="kv k" x={s.x + 26} y="167">
1 socket
</text>
</g>
))
}
<path class="lead" d="M101 180 V 212"></path>
<path class="lead" d="M409 180 V 212"></path>
<path class="lead" d="M600 180 V 230"></path>
<text class="code" x="28" y="224">GetChannel("data-in")</text>
<text class="code" x="336" y="224">GetChannel("data-out", 0)</text>
<text class="code" x="490" y="242">GetChannel("data-out", 1)</text>
</svg>
<figcaption>
A channel has a name and one or more sub-channels. Each sub-channel owns one socket, with its own type, method and address. The index of the sub-channel is the
second argument of <code>GetChannel()</code>, and the third argument of <code>Send()</code> and <code>Receive()</code>. The default index is 0.
</figcaption>
</figure>
<style>
.fmq-chan {
margin: 1.5rem 0;
}
svg {
width: 100%;
height: auto;
display: block;
}
.dev {
fill: var(--fmq-paper-2);
stroke: var(--fmq-ink-2);
stroke-width: 1.2;
}
.ch {
fill: var(--fmq-paper);
stroke: var(--fmq-rule-strong);
stroke-width: 1.2;
}
.sub {
fill: var(--fmq-paper);
stroke: var(--fmq-ink-3);
stroke-dasharray: 4 3;
}
.sock {
fill: var(--fmq-saffron);
stroke: var(--fmq-bar);
}
.lead {
fill: none;
stroke: var(--fmq-ink-3);
stroke-width: 1;
stroke-dasharray: 2 3;
}
.dev-l {
font: 700 13px var(--fmq-font-mono);
fill: var(--fmq-ink);
}
.ch-l {
font: 600 12px var(--fmq-font-mono);
fill: var(--fmq-ink);
}
.sub-l {
font: 600 11px var(--fmq-font-mono);
fill: var(--fmq-ink-2);
}
.kv {
font: 400 11px var(--fmq-font-mono);
fill: var(--fmq-ink);
}
.k {
fill: var(--fmq-ink-3);
}
.addr {
fill: var(--fmq-accent-ink);
}
.code {
font: 600 11px var(--fmq-font-mono);
fill: var(--fmq-link);
}
figcaption {
font-size: 0.85rem;
color: var(--fmq-ink-3);
margin-top: 0.5rem;
}
figcaption code {
font-size: 0.8em;
}
</style>

View File

@@ -0,0 +1,331 @@
---
// A step-by-step explainer: a dark stage with an SVG, a caption, a line of code and controls.
// The slot holds the SVG. It must have the attribute data-stage. For step n (1-based), the
// script sets the classes r1 … rn and now<n> on the SVG, so CSS can show each step. Elements
// with data-slot="name" get the text of step.set[name].
interface Step {
cap: string;
code?: string;
set?: Record<string, string>;
}
interface Props {
title: string;
meta?: string;
steps: Step[];
}
const { title, meta, steps } = Astro.props;
---
<div class="fmq-ex not-content" tabindex="0" aria-label={`${title}. Explainer in ${steps.length} steps. Use the arrow keys to step.`} data-steps={JSON.stringify(steps)}>
<div class="ex-top">
<b>{title}</b>
{meta && <span>{meta}</span>}
</div>
<slot />
<div class="ex-foot">
<p class="ex-cap" aria-live="polite">{steps[0].cap}</p>
<code class="ex-line">{steps[0].code}</code>
</div>
<div class="ex-ctl">
<button class="ex-b" type="button" data-act="restart" aria-label="Start again"
><svg viewBox="0 0 14 14" aria-hidden="true"><path d="M3 2v10" stroke="currentColor" stroke-width="1.6"></path><path d="M12 2L5 7l7 5z" fill="currentColor"></path></svg></button
>
<button class="ex-b" type="button" data-act="prev" aria-label="Previous step"
><svg viewBox="0 0 14 14" aria-hidden="true"><path d="M10 2L4 7l6 5z" fill="currentColor"></path></svg></button
>
<button class="ex-b" type="button" data-act="play" aria-label="Play" data-state="play"
><svg class="i-play" viewBox="0 0 14 14" aria-hidden="true"><path d="M3 2l9 5-9 5z" fill="currentColor"></path></svg><svg
class="i-pause"
viewBox="0 0 14 14"
aria-hidden="true"><path d="M3 2h3v10H3zM8 2h3v10H8z" fill="currentColor"></path></svg
></button
>
<button class="ex-b" type="button" data-act="next" aria-label="Next step"
><svg viewBox="0 0 14 14" aria-hidden="true"><path d="M4 2l6 5-6 5z" fill="currentColor"></path></svg></button
>
<div class="ex-ticks">
{
steps.map((_, k) => (
<button type="button" aria-label={`Step ${k + 1}`} data-step={k}>
{k + 1}
</button>
))
}
</div>
<span class="ex-count">1 / {steps.length}</span>
</div>
<details class="ex-text">
<summary>All steps as text</summary>
<ol>
{
steps.map((s) => (
<li>
{s.cap}
{s.code && (
<>
{' '}
<code>{s.code}</code>
</>
)}
</li>
))
}
</ol>
</details>
</div>
<script>
for (const root of document.querySelectorAll<HTMLElement>('.fmq-ex')) {
const steps: { cap: string; code?: string; set?: Record<string, string> }[] = JSON.parse(root.dataset.steps!);
const svg = root.querySelector<SVGSVGElement>('svg[data-stage]')!;
const baseClass = svg.getAttribute('class') ?? '';
const cap = root.querySelector('.ex-cap')!;
const line = root.querySelector<HTMLElement>('.ex-line')!;
const play = root.querySelector<HTMLButtonElement>('[data-act=play]')!;
const count = root.querySelector('.ex-count')!;
const ticks = [...root.querySelectorAll<HTMLButtonElement>('[data-step]')];
const slots = [...svg.querySelectorAll<SVGElement>('[data-slot]')];
const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
let i = 0;
let playing = false;
let timer = 0;
let seen = false;
const show = (n: number) => {
i = Math.max(0, Math.min(steps.length - 1, n));
const st = i + 1;
const c = [baseClass];
for (let k = 1; k <= st; k++) c.push('r' + k);
c.push('now' + st);
svg.setAttribute('class', c.join(' ').trim());
cap.textContent = steps[i].cap;
line.textContent = steps[i].code ?? '';
line.hidden = !steps[i].code;
for (const el of slots) el.textContent = steps[i].set?.[el.dataset.slot!] ?? '';
ticks.forEach((b, k) => {
b.classList.toggle('done', k < i);
b.classList.toggle('on', k === i);
if (k === i) b.setAttribute('aria-current', 'step');
else b.removeAttribute('aria-current');
});
count.textContent = `${st} / ${steps.length}`;
};
const pause = () => {
playing = false;
clearTimeout(timer);
play.dataset.state = 'play';
play.setAttribute('aria-label', 'Play');
};
const step = () => {
if (!playing) return;
if (i >= steps.length - 1) return pause();
show(i + 1);
timer = window.setTimeout(step, 4200);
};
const start = () => {
if (i >= steps.length - 1) show(0);
playing = true;
play.dataset.state = 'pause';
play.setAttribute('aria-label', 'Pause');
clearTimeout(timer);
timer = window.setTimeout(step, 3400);
};
root.addEventListener('click', (e) => {
const b = (e.target as HTMLElement).closest('button');
if (!b) return;
const act = b.dataset.act;
if (act === 'play') return playing ? pause() : start();
pause();
if (act === 'prev') show(i - 1);
else if (act === 'next') show(i + 1);
else if (act === 'restart') show(0);
else if (b.dataset.step) show(Number(b.dataset.step));
});
root.addEventListener('keydown', (e) => {
if (e.key === 'ArrowRight' || e.key === 'ArrowLeft') {
e.preventDefault();
pause();
show(i + (e.key === 'ArrowRight' ? 1 : -1));
}
});
show(0);
if (!reduce && 'IntersectionObserver' in window) {
new IntersectionObserver(
(es) => {
for (const e of es) {
if (e.isIntersecting && !seen) {
seen = true;
start();
} else if (!e.isIntersecting && playing) pause();
}
},
{ threshold: 0.6 }
).observe(svg);
}
}
</script>
<style>
.fmq-ex {
background: var(--fmq-stage);
color: var(--fmq-stage-ink);
border: 1px solid var(--fmq-stage-rule);
border-radius: 6px;
overflow: hidden;
margin-block: 1.5rem;
}
.fmq-ex:focus-visible {
outline: 2px solid var(--fmq-sky-bright);
outline-offset: 2px;
}
.ex-top {
display: flex;
justify-content: space-between;
gap: 0.6rem;
align-items: center;
padding: 0.75rem 1rem 0;
flex-wrap: wrap;
}
.ex-top b {
font: 800 0.95rem/1.2 var(--fmq-font-body);
font-stretch: 110%;
}
.ex-top span {
font: 500 0.75rem/1 var(--fmq-font-mono);
color: var(--fmq-stage-dim);
}
.fmq-ex :global(svg[data-stage]) {
width: 100%;
height: auto;
display: block;
}
.fmq-ex :global(svg[data-stage] text) {
font-family: var(--fmq-font-mono);
}
.ex-foot {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 0.6rem;
padding: 0.25rem 1.1rem 1rem;
}
.ex-cap {
font-size: 1.05rem;
line-height: 1.5;
margin: 0;
min-height: 4.6em;
max-width: 66ch;
color: var(--fmq-stage-ink);
}
code.ex-line {
font: 500 0.8125rem/1.4 var(--fmq-font-mono);
color: var(--fmq-saffron);
background: var(--fmq-stage-2);
border: 1px solid var(--fmq-stage-rule);
border-radius: 3px;
padding: 0.4rem 0.6rem;
justify-self: start;
max-width: 100%;
overflow-x: auto;
white-space: nowrap;
}
code.ex-line[hidden] {
display: block;
visibility: hidden;
}
.ex-ctl {
display: flex;
align-items: center;
gap: 0.5rem;
flex-wrap: wrap;
border-top: 1px solid var(--fmq-stage-rule);
padding: 0.6rem 0.9rem;
background: var(--fmq-stage-2);
}
.ex-b {
width: 34px;
height: 32px;
display: inline-grid;
place-items: center;
border: 1px solid var(--fmq-stage-line);
background: transparent;
color: var(--fmq-stage-ink);
border-radius: 4px;
cursor: pointer;
padding: 0;
}
.ex-b:hover {
border-color: var(--fmq-stage-dim);
}
.ex-b svg {
width: 14px;
height: 14px;
}
.ex-b .i-pause {
display: none;
}
.ex-b[data-state='pause'] .i-pause {
display: block;
}
.ex-b[data-state='pause'] .i-play {
display: none;
}
.ex-ticks {
display: flex;
gap: 5px;
margin-inline-start: 0.4rem;
flex-wrap: wrap;
}
.ex-ticks button {
width: 24px;
height: 24px;
border: 1px solid var(--fmq-stage-line);
background: transparent;
color: var(--fmq-stage-dim);
font: 600 0.66rem/1 var(--fmq-font-mono);
cursor: pointer;
padding: 0;
border-radius: 2px;
}
.ex-ticks button:global(.done) {
background: var(--fmq-stage-line);
color: var(--fmq-stage-ink);
}
.ex-ticks button:global(.on) {
background: var(--fmq-saffron);
border-color: var(--fmq-saffron);
color: var(--fmq-on-saffron);
}
.ex-count {
margin-inline-start: auto;
font: 500 0.75rem/1 var(--fmq-font-mono);
color: var(--fmq-stage-dim);
}
.ex-text {
border-top: 1px solid var(--fmq-stage-rule);
padding: 0.55rem 1rem;
font-size: 0.875rem;
color: var(--fmq-stage-dim);
}
.ex-text summary {
cursor: pointer;
font-weight: 500;
}
.ex-text ol {
margin: 0.5rem 0 0.25rem;
padding-inline-start: 1.4rem;
color: var(--fmq-stage-ink);
line-height: 1.55;
}
.ex-text li + li {
margin-top: 0.35rem;
}
.ex-text code {
font: 500 0.78rem var(--fmq-font-mono);
color: var(--fmq-saffron);
overflow-wrap: anywhere;
}
@media print {
.ex-ctl {
display: none;
}
}
</style>

View File

@@ -0,0 +1,125 @@
---
// The four common socket patterns. Socket types: fairmq/Channel.cxx (Validate).
// shmem rejects pub and sub: fairmq/shmem/Socket.h.
const patterns = [
{ a: 'push', b: 'pull', fan: true, cap: 'push → pull', m: 'round-robin', both: 1 },
{ a: 'pub', b: 'sub', fan: true, cap: 'pub → sub', m: 'a copy to each', both: 2, note: 'zeromq only' },
{ a: 'req', b: 'rep', fan: false, cap: 'req ⇄ rep', m: 'request, then reply' },
{ a: 'pair', b: 'pair', fan: false, cap: 'pair ⇄ pair', m: 'two peers only' },
];
---
<figure class="fmq-pat not-content">
<svg viewBox="0 0 600 150" role="img" aria-label="Four socket patterns: push to pull, pub to sub, req and rep, pair and pair.">
<defs>
<marker id="pat-a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"
><path d="M0 0L10 5L0 10z" class="ah"></path></marker
>
</defs>
{
patterns.map((p, i) => (
<g transform={`translate(${i * 152} 0)`}>
<rect class="box" x="4" y="40" width="46" height="26" />
<text class="t" x="27" y="57" text-anchor="middle">
{p.a}
</text>
{p.fan ? (
<>
<rect class="box" x="92" y="10" width="46" height="26" />
<text class="t" x="115" y="27" text-anchor="middle">
{p.b}
</text>
<rect class="box" x="92" y="70" width="46" height="26" />
<text class="t" x="115" y="87" text-anchor="middle">
{p.b}
</text>
<path class="line" d="M50 50 L92 24" marker-end="url(#pat-a)" />
<path class="line" d="M50 56 L92 82" marker-end="url(#pat-a)" />
<rect class="msg" x="67" y="32" width="7" height="7" />
{p.both === 2 && <rect class="msg" x="67" y="66" width="7" height="7" />}
</>
) : (
<>
<rect class="box" x="92" y="40" width="46" height="26" />
<text class="t" x="115" y="57" text-anchor="middle">
{p.b}
</text>
<path class="line" d="M50 47 L92 47" marker-end="url(#pat-a)" />
<path class="line" d="M92 59 L50 59" marker-end="url(#pat-a)" />
</>
)}
<text class="cap" x="4" y="118">
{p.cap}
</text>
<text class="m" x="4" y="134">
{p.m}
</text>
{p.note && (
<text class="note" x="4" y="148">
{p.note}
</text>
)}
</g>
))
}
</svg>
<figcaption>
FairMQ also accepts <code>dealer</code>, <code>router</code>, <code>xpub</code> and <code>xsub</code>. The shmem transport does not support <code>pub</code> and <code>sub</code>.
</figcaption>
</figure>
<style>
.fmq-pat {
margin: 1.5rem 0;
border-top: 1px solid var(--fmq-rule);
border-bottom: 1px solid var(--fmq-rule);
padding: 0.9rem 0 0.6rem;
}
svg {
width: 100%;
height: auto;
display: block;
}
.box {
fill: var(--fmq-paper);
stroke: var(--fmq-ink-2);
stroke-width: 1.2;
}
.line {
stroke: var(--fmq-ink-3);
stroke-width: 1.2;
fill: none;
}
.ah {
fill: var(--fmq-ink-3);
}
.msg {
fill: var(--fmq-saffron);
stroke: var(--fmq-bar);
stroke-width: 1;
}
.t {
font: 600 11.5px var(--fmq-font-mono);
fill: var(--fmq-ink);
}
.m {
font: 400 10.5px var(--fmq-font-mono);
fill: var(--fmq-ink-3);
}
.note {
font: 600 10px var(--fmq-font-mono);
fill: var(--fmq-ruby);
}
.cap {
font: 600 12px var(--fmq-font-body);
fill: var(--fmq-ink);
}
figcaption {
font-size: 0.85rem;
color: var(--fmq-ink-3);
margin-top: 0.5rem;
}
figcaption code {
font-size: 0.8em;
}
</style>

View File

@@ -0,0 +1,352 @@
---
// How the creator of an unmanaged region learns that its blocks are free again.
// Facts: fairmq/shmem/UnmanagedRegion.h (ReleaseBlock, SendAcks, ReceiveAcks, fAckBunchSize = 256,
// wait_for 500 ms, queue name "rgq", bulk callback or one call per block), Manager.h (with a callback the
// creator starts an ack receiver and an ack sender; a device that opens a remote region starts an ack
// sender), Message.h (GetData opens the region, Deallocate).
import Explainer from './Explainer.astro';
const steps = [
{
cap: 'The sampler creates an unmanaged region and gives a bulk callback. The memory of the region belongs to the sampler. Because of the callback, FairMQ starts an ack receiver in the sampler. It also starts an ack sender there, for messages that come back.',
code: 'auto region = NewUnmanagedRegionFor("data", 0, 10000000, callback);',
set: { a: 'NewUnmanagedRegionFor(…)' },
},
{
cap: 'The sampler writes data into the region and makes messages that point to it. The transport allocates no memory in the managed segment for these messages.',
code: 'auto msg = NewMessageFor("data", 0, region, ptr, size, hint);',
set: { a: 'NewMessageFor(…)' },
},
{
cap: 'Send() puts only a MetaHeader for each message into the socket. The data stays in the region.',
code: 'Send(parts, "data");',
set: { a: 'Send(parts, "data")' },
},
{
cap: 'The sink receives the messages. At the first GetData(), the sink opens the region and reads the data in place. FairMQ starts an ack sender in the sink.',
code: 'Receive(parts, "data");',
set: { b: 'Receive(parts, "data")' },
},
{
cap: 'The sink destroys the messages. The transport puts each block, with its size and its hint, into a list in the sink.',
code: '} // parts are destroyed: the blocks go into the list',
set: { b: '~Message()' },
},
{
cap: 'The ack sender sends the list as one bunch into the region queue. It sends when the list holds 256 blocks, or after 500 ms.',
code: 'fmq_<shmId>_rgq_<regionId>',
},
{
cap: 'The ack receiver of the sampler gets the bunch. It calls the bulk callback one time with all blocks of the bunch: pointer, size and hint. A RegionCallback runs one time for each block.',
code: '[](const std::vector<fair::mq::RegionBlock>& blocks) { … }',
set: { a: 'callback(blocks)' },
},
{
cap: 'In the callback, the sampler marks the blocks as free. Then it can write new data into them.',
code: 'fNumUnackedMsgs -= blocks.size();',
set: { a: 'blocks are free' },
},
];
const blocks = [96, 196, 296, 396];
---
<Explainer title="Free blocks of an unmanaged region" meta="sampler → sink · same host" steps={steps}>
<svg class="ra" data-stage viewBox="0 0 720 330" role="img" aria-label="The acknowledgement of unmanaged region blocks">
<defs>
<pattern id="ra-cells" width="16" height="72" patternUnits="userSpaceOnUse"><line x1="0.5" y1="0" x2="0.5" y2="72" class="cell"></line></pattern>
<pattern id="ra-stripes" width="8" height="8" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"><rect width="3" height="8" class="stripe"></rect></pattern>
<marker id="ra-arr" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"
><path d="M0 0L10 5L0 10z" class="arrhead"></path></marker
>
<marker id="ra-arr-sky" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"
><path d="M0 0L10 5L0 10z" class="arrhead-sky"></path></marker
>
</defs>
<!-- channel and region queue -->
<line x1="260" y1="58" x2="460" y2="58" class="chan"></line>
<text x="360" y="48" text-anchor="middle" class="sub">channel "data"</text>
<g class="queue">
<rect x="262" y="104" width="196" height="22" rx="2" class="qbox"></rect>
<path d="M440 115 H 282" class="qdir" marker-end="url(#ra-arr)"></path>
<text x="360" y="96" text-anchor="middle" class="sub">region queue</text>
</g>
<!-- mappings -->
<line x1="150" y1="140" x2="150" y2="206" class="map map-a"></line>
<line x1="570" y1="140" x2="570" y2="206" class="map map-b"></line>
<!-- region -->
<g class="region">
<rect x="40" y="206" width="640" height="72" rx="2" class="segbox"></rect>
<rect x="40" y="206" width="640" height="72" fill="url(#ra-cells)"></rect>
<text x="40" y="298" class="sub">/dev/shm/fmq_&lt;shmId&gt;_rg_&lt;regionId&gt;</text>
<text x="680" y="298" text-anchor="end" class="sub">unmanaged region · memory of the sampler</text>
</g>
{
blocks.map((x) => (
<g class="rb">
<rect x={x} y="224" width="80" height="36" class="rb-free" />
<rect x={x} y="224" width="80" height="36" class="rb-data" />
<rect x={x} y="224" width="80" height="36" fill="url(#ra-stripes)" class="rb-rel" />
</g>
))
}
<text class="lbl-data sub" x="536" y="247">data</text>
<text class="lbl-rel sub ruby" x="496" y="247">released by the sink</text>
<text class="lbl-free sub mint" x="496" y="247">free again</text>
<path class="hdl" d="M556 140 C 540 180, 500 196, 470 222" marker-end="url(#ra-arr-sky)"></path>
<text class="hdllabel sub sky" x="530" y="196" text-anchor="end">read in place</text>
<!-- processes -->
<g class="proc">
<rect x="40" y="20" width="220" height="120" rx="3"></rect>
<text x="58" y="46" class="name">sampler</text>
<text x="58" y="64" class="sub">creates the region</text>
<text x="58" y="90" class="code" data-slot="a"></text>
<g class="thr thr-a">
<rect x="58" y="104" width="112" height="22" rx="11"></rect>
<text x="114" y="119" text-anchor="middle">ack receiver</text>
</g>
<g class="cb">
<rect x="178" y="104" width="68" height="22" rx="3"></rect>
<text x="212" y="119" text-anchor="middle">callback</text>
</g>
</g>
<g class="proc">
<rect x="460" y="20" width="220" height="120" rx="3"></rect>
<text x="478" y="46" class="name">sink</text>
<text x="478" y="64" class="sub">opens the region</text>
<text x="478" y="90" class="code" data-slot="b"></text>
<g class="thr thr-b">
<rect x="478" y="104" width="100" height="22" rx="11"></rect>
<text x="528" y="119" text-anchor="middle">ack sender</text>
</g>
</g>
<!-- list of released blocks in the sink -->
<g class="list">
<rect x="590" y="108" width="14" height="14" class="lst"></rect>
<rect x="608" y="108" width="14" height="14" class="lst"></rect>
<rect x="626" y="108" width="14" height="14" class="lst"></rect>
<rect x="644" y="108" width="14" height="14" class="lst"></rect>
</g>
<!-- the bunch on its way through the queue -->
<g class="bunch">
<rect x="590" y="108" width="68" height="14" class="lst"></rect>
<text x="624" y="146" text-anchor="middle" class="sub sky">bunch · ≤ 256 blocks</text>
</g>
<!-- MetaHeaders on the channel -->
<g class="metas">
<rect x="248" y="51" width="14" height="14" class="metabox"></rect>
<rect x="230" y="51" width="14" height="14" class="metabox m2"></rect>
</g>
</svg>
</Explainer>
<style>
.name {
fill: var(--fmq-stage-ink);
font-size: 16px;
font-weight: 700;
}
.sub {
fill: var(--fmq-stage-dim);
font-size: 11.5px;
}
.code {
fill: var(--fmq-saffron);
font-size: 11.5px;
font-weight: 600;
}
.sky {
fill: var(--fmq-sky-bright);
}
.mint {
fill: var(--fmq-mint);
font-weight: 700;
}
.ruby {
fill: var(--fmq-ruby);
font-weight: 700;
}
.proc > rect {
fill: var(--fmq-stage-2);
stroke: var(--fmq-stage-line);
stroke-width: 1.2;
}
.chan {
stroke: var(--fmq-stage-line);
stroke-width: 1.5;
}
.qbox {
fill: var(--fmq-stage-2);
stroke: var(--fmq-stage-line);
}
.qdir {
stroke: var(--fmq-stage-line);
stroke-width: 1.2;
fill: none;
}
.arrhead {
fill: var(--fmq-stage-line);
}
.map {
stroke: var(--fmq-stage-line);
stroke-dasharray: 4 4;
stroke-width: 1.2;
}
.segbox {
fill: var(--fmq-stage-2);
stroke: var(--fmq-stage-line);
}
.cell {
stroke: var(--fmq-stage-cell);
stroke-width: 1;
}
.stripe {
fill: var(--fmq-ruby);
opacity: 0.55;
}
.rb-free {
fill: none;
stroke: var(--fmq-stage-line);
stroke-dasharray: 3 3;
}
.rb-data {
fill: var(--fmq-saffron);
}
.rb-rel {
stroke: var(--fmq-ruby);
stroke-width: 1.5;
}
.thr rect {
fill: none;
stroke: var(--fmq-sky-bright);
stroke-width: 1.2;
}
.thr text,
.cb text {
font-size: 10.5px;
font-weight: 600;
fill: var(--fmq-sky-bright);
}
.cb rect {
fill: none;
stroke: var(--fmq-stage-line);
stroke-width: 1.2;
transition:
fill 0.4s,
stroke 0.4s;
}
.cb text {
fill: var(--fmq-stage-dim);
transition: fill 0.4s;
}
.ra.now7 .cb rect {
fill: var(--fmq-saffron);
stroke: var(--fmq-saffron);
}
.ra.now7 .cb text {
fill: var(--fmq-on-saffron);
}
.lst {
fill: var(--fmq-ruby);
}
.metabox {
fill: var(--fmq-sky-bright);
}
.hdl {
fill: none;
stroke: var(--fmq-sky-bright);
stroke-width: 1.6;
stroke-dasharray: 5 4;
}
.arrhead-sky {
fill: var(--fmq-sky-bright);
}
/* Choreography. Hidden first, then shown by step. */
.region,
.map-a,
.thr-a,
.cb,
.rb,
.map-b,
.thr-b,
.hdl,
.hdllabel,
.lbl-data,
.lbl-rel,
.lbl-free,
.list,
.bunch,
.metas,
.rb-data,
.rb-rel {
opacity: 0;
transition: opacity 0.5s;
}
.ra.r1 .region,
.ra.r1 .map-a,
.ra.r1 .thr-a,
.ra.r1 .cb,
.ra.r1 .rb {
opacity: 1;
}
.ra.r2 .rb-data,
.ra.now2 .lbl-data,
.ra.now3 .lbl-data,
.ra.now4 .lbl-data {
opacity: 1;
}
.metas {
transform: translate(0, 0);
transition:
transform 1.6s cubic-bezier(0.45, 0, 0.2, 1),
opacity 0.35s;
}
.ra.now3 .metas {
opacity: 1;
transform: translate(196px, 0);
}
.ra.r4 .map-b,
.ra.r4 .thr-b,
.ra.now4 .hdl,
.ra.now4 .hdllabel {
opacity: 1;
}
.ra.r5 .rb-rel,
.ra.now5 .lbl-rel,
.ra.now6 .lbl-rel,
.ra.now7 .lbl-rel,
.ra.now5 .list {
opacity: 1;
}
.bunch {
transform: translate(0, 0);
transition:
transform 1.8s cubic-bezier(0.45, 0, 0.2, 1),
opacity 0.35s;
}
.ra.now6 .bunch {
opacity: 1;
transform: translate(-216px, 0);
}
.ra.now7 .bunch {
opacity: 1;
transform: translate(-330px, 0);
}
.ra.r8 .rb-data,
.ra.r8 .rb-rel {
opacity: 0;
}
.ra.now8 .lbl-free {
opacity: 1;
}
@media (prefers-reduced-motion: reduce) {
.ra * {
transition: none !important;
}
}
</style>

View File

@@ -0,0 +1,162 @@
---
// The shared memory objects of one session. Names: fairmq/shmem/Common.h (MakeShmName) and the
// callers in Manager.h, UnmanagedRegion.h and Monitor.cxx. Sizes: kManagementSegmentSize,
// --shm-segment-size, RegionConfig::rcSegmentSize.
const rows = [
{ name: 'fmq_eca859e3_mng', kind: 'management segment', size: '6.25 MiB', w: 18, what: 'The session info, the heartbeat, the counters of devices, events and automatic region IDs, and the lists of segments and regions.' },
{ name: 'fmq_eca859e3_m_0', kind: 'managed segment', size: '--shm-segment-size, 2 GiB', w: 100, what: 'The buffers of NewMessage(). More segments are possible: _m_1, _m_2 …', accent: true },
{ name: 'fmq_eca859e3_rg_<id>', kind: 'unmanaged region', size: 'size from the creator', w: 60, what: 'Memory that a device creates with NewUnmanagedRegion() and fills itself.', accent: true },
{ name: 'fmq_eca859e3_rrc_<id>', kind: 'reference counts', size: 'rcSegmentSize, 100 MB', w: 34, what: 'The reference counts of copied region messages. It exists only if rcSegmentSize is more than 0.' },
{ name: 'fmq_eca859e3_rgq_<id>', kind: 'message queue', size: '1024 bunches of up to 6 KiB', w: 18, what: 'The acknowledgements of region blocks, back to the creator of the region.' },
{ name: 'sem.fmq_eca859e3_ms', kind: 'named mutex', size: '', w: 2, what: 'fairmq-shmmonitor creates it. It shows that a monitor runs for the session.' },
];
---
<figure class="fmq-map not-content">
<div class="map-id">
<span>user ID <code>1000</code></span>
<span class="op">+</span>
<span>session <code>default</code></span>
<span class="op">→ SHA-256 → first 4 bytes →</span>
<span>shmId <code class="hl">eca859e3</code></span>
</div>
<ol class="map-rows">
{
rows.map((r) => (
<li class={r.accent ? 'accent' : ''}>
<div class="map-name">
<code>/dev/shm/{r.name}</code>
<span class="map-kind">{r.kind}</span>
</div>
<div class="map-bar" aria-hidden="true">
<i style={`width:${r.w}%`} />
</div>
<p class="map-what">
{r.what} {r.size && <span class="map-size">{r.size}</span>}
</p>
</li>
))
}
</ol>
<figcaption>
All devices with the same session name and the same user open the same objects. The last device that leaves removes them, unless <code>--shm-no-cleanup</code> is true. It does not remove the
mutex of the monitor. A region with a path is a file in that path, not an object in <code>/dev/shm</code>. Bars show the size only roughly.
</figcaption>
</figure>
<style>
.fmq-map {
margin: 1.5rem 0;
border: 1px solid var(--fmq-rule);
border-radius: 6px;
background: var(--fmq-paper);
overflow: hidden;
}
.map-id {
display: flex;
flex-wrap: wrap;
gap: 0.35rem 0.6rem;
align-items: baseline;
padding: 0.75rem 1rem;
background: var(--fmq-paper-2);
border-bottom: 1px solid var(--fmq-rule);
font-size: 0.875rem;
color: var(--fmq-ink-2);
}
.map-id .op {
color: var(--fmq-ink-3);
font-size: 0.8125rem;
}
code {
font-family: var(--fmq-font-mono);
font-size: 0.8125rem;
color: var(--fmq-ink);
}
code.hl {
background: var(--fmq-saffron-tint);
border: 1px solid var(--fmq-bar);
border-radius: 3px;
padding: 0 0.3em;
}
.map-rows {
list-style: none;
margin: 0;
padding: 0;
}
.map-rows li {
display: grid;
grid-template-columns: minmax(0, 17rem) minmax(0, 1fr);
gap: 0.25rem 1rem;
padding: 0.65rem 1rem;
border-bottom: 1px solid var(--fmq-rule);
margin: 0;
}
.map-rows li:last-child {
border-bottom: 0;
}
.map-name {
display: flex;
flex-direction: column;
gap: 0.15rem;
min-width: 0;
}
.map-name code {
font-weight: 600;
overflow-wrap: anywhere;
}
.map-kind {
font: 600 0.66rem/1.3 var(--fmq-font-body);
letter-spacing: 0.1em;
text-transform: uppercase;
color: var(--fmq-ink-3);
}
.map-bar {
grid-column: 2;
grid-row: 1;
align-self: center;
height: 10px;
border: 1px solid var(--fmq-rule-strong);
border-radius: 2px;
background: var(--fmq-paper-2);
}
.map-bar i {
display: block;
height: 100%;
min-width: 3px;
background: var(--fmq-ink-3);
}
.accent .map-bar i {
background: var(--fmq-saffron);
}
.map-what {
grid-column: 2;
margin: 0;
font-size: 0.875rem;
color: var(--fmq-ink-2);
line-height: 1.45;
}
.map-size {
font: 500 0.75rem var(--fmq-font-mono);
color: var(--fmq-ink-3);
white-space: nowrap;
}
figcaption {
font-size: 0.85rem;
color: var(--fmq-ink-3);
padding: 0.6rem 1rem 0.75rem;
border-top: 1px solid var(--fmq-rule);
}
figcaption code {
font-size: 0.8em;
}
@media (max-width: 40rem) {
.map-rows li {
grid-template-columns: minmax(0, 1fr);
}
.map-bar,
.map-what {
grid-column: 1;
grid-row: auto;
}
}
</style>

View File

@@ -0,0 +1,580 @@
---
// Interactive state machine of a FairMQ device.
// The layout follows the diagram that `--control interactive` prints (fairmq/plugins/control/Control.cxx).
// States and transitions come from fairmq/States.h and fairmq/StateMachine.cxx.
const H = 38;
type Kind = 'idle' | 'work' | 'end' | 'error';
const N: Record<string, [number, number, number, Kind]> = {
IDLE: [16, 24, 296, 'idle'],
EXITING: [344, 24, 60, 'end'],
'INITIALIZING DEVICE': [16, 86, 236, 'work'],
'RESETTING DEVICE': [276, 86, 128, 'work'],
INITIALIZED: [16, 148, 236, 'idle'],
BINDING: [16, 210, 236, 'work'],
BOUND: [16, 272, 236, 'idle'],
CONNECTING: [16, 334, 236, 'work'],
'DEVICE READY': [16, 396, 388, 'idle'],
'INITIALIZING TASK': [16, 458, 236, 'work'],
'RESETTING TASK': [276, 458, 128, 'work'],
READY: [16, 520, 388, 'idle'],
RUNNING: [16, 582, 388, 'work'],
ERROR: [16, 652, 388, 'error'],
};
// [from, to, transition, key, path points, label position]
const E: [string, string, string, string, number[][], number[]][] = [
['IDLE', 'INITIALIZING DEVICE', 'InitDevice', 'i', [[134, 62], [134, 86]], [148, 74]],
['IDLE', 'EXITING', 'End', 'q', [[312, 43], [344, 43]], [328, 43]],
['INITIALIZING DEVICE', 'INITIALIZED', 'CompleteInit', '', [[134, 124], [134, 148]], [142, 139]],
['INITIALIZED', 'BINDING', 'Bind', 'b', [[134, 186], [134, 210]], [148, 198]],
['INITIALIZED', 'RESETTING DEVICE', 'ResetDevice', 'd', [[252, 167], [340, 167], [340, 124]], [296, 167]],
['BINDING', 'BOUND', 'Auto', '', [[134, 248], [134, 272]], [142, 263]],
['BOUND', 'CONNECTING', 'Connect', 'x', [[134, 310], [134, 334]], [148, 322]],
['BOUND', 'RESETTING DEVICE', 'ResetDevice', 'd', [[252, 291], [340, 291], [340, 124]], [296, 291]],
['CONNECTING', 'DEVICE READY', 'Auto', '', [[134, 372], [134, 396]], [142, 387]],
['DEVICE READY', 'INITIALIZING TASK', 'InitTask', 'j', [[134, 434], [134, 458]], [148, 446]],
['DEVICE READY', 'RESETTING DEVICE', 'ResetDevice', 'd', [[340, 396], [340, 124]], [354, 382]],
['INITIALIZING TASK', 'READY', 'Auto', '', [[134, 496], [134, 520]], [142, 511]],
['READY', 'RESETTING TASK', 'ResetTask', 't', [[340, 520], [340, 496]], [354, 508]],
['RESETTING TASK', 'DEVICE READY', 'Auto', '', [[340, 458], [340, 434]], [348, 449]],
['READY', 'RUNNING', 'Run', 'r', [[134, 558], [134, 582]], [148, 570]],
['RUNNING', 'READY', 'Stop', 's', [[300, 582], [300, 558]], [314, 570]],
['RESETTING DEVICE', 'IDLE', 'Auto', '', [[296, 86], [296, 62]], [304, 77]],
];
const I: Record<string, [string, string, string]> = {
IDLE: [
'Idling state',
'The state machine starts here. The device has no channels yet. The config plugin reads --mq-config or --channel-config when INITIALIZING DEVICE starts.',
'—',
],
'INITIALIZING DEVICE': [
'Working state',
'The device waits for CompleteInit. A controller can set properties now. Then the device calls Init(), reads rate, init-timeout and transport, and makes the transports and the channels.',
'Init()',
],
INITIALIZED: ['Idling state', 'The configuration is complete and the channels exist. Nothing is bound or connected yet.', '—'],
BINDING: ['Working state', 'The device binds all channels with the method bind. Then it calls Bind().', 'Bind()'],
BOUND: ['Idling state', 'All channels with the method bind have an endpoint.', '—'],
CONNECTING: [
'Working state',
'The device connects all channels with the method connect. If an address is not valid yet, it tries again every 50 ms. After init-timeout (default 120 s), it goes to ERROR. When all channels are connected, it calls Connect().',
'Connect()',
],
'DEVICE READY': ['Idling state', 'All channels are bound or connected.', '—'],
'INITIALIZING TASK': ['Working state', 'The device prepares the task. Read your own options and allocate resources here.', 'InitTask()'],
READY: ['Idling state', 'The task is ready. The device waits for Run.', '—'],
RUNNING: [
'Working state',
'The device calls PreRun(). Then it calls your OnData() callbacks, or it calls ConditionalRun() until it returns false or a transition is pending, and then Run(). If no transition is pending, the device requests Stop. It calls PostRun() and then goes to READY.',
'PreRun() · OnData() or ConditionalRun() and Run() · PostRun()',
],
'RESETTING TASK': ['Working state', 'The device calls ResetTask(). Undo the work of InitTask() here.', 'ResetTask()'],
'RESETTING DEVICE': ['Working state', 'The device resets and removes its transports, calls Reset(), and removes all channels.', 'Reset()'],
EXITING: ['Final state', 'The state machine stops. The device process can end.', '—'],
ERROR: [
'Error state',
'An exception in a hook, or the transition ErrorFound, moves the device here. No transition leaves ERROR. The controller stops without the shutdown sequence, so ResetTask() and Reset() do not run. The process ends with the exit code 1.',
'—',
],
};
const data = JSON.stringify({ N, E: E.map(([f, t, n, k]) => [f, t, n, k]), I });
const d = (pts: number[][]) => 'M' + pts.map((p) => p.join(' ')).join(' L');
---
<div class="fmq-sm not-content" data-sm={data}>
<div class="sm-fig">
<svg viewBox="0 0 420 700" role="group" aria-label="State machine of a FairMQ device">
<defs>
<marker id="sm-arr" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"
><path d="M0 0L10 5L0 10z" class="sm-ah"></path></marker
>
<marker id="sm-arr-on" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"
><path d="M0 0L10 5L0 10z" class="sm-ah-on"></path></marker
>
</defs>
<g>
{E.map((e, i) => <path d={d(e[4])} class="sm-e" marker-end="url(#sm-arr)" data-edge={i} />)}
</g>
<g>
{
Object.entries(N).map(([name, [x, y, w, k]]) => (
<g class={`sm-n sm-${k}`} tabindex="0" role="button" aria-label={`${name}: show details`} data-state={name}>
<rect x={x} y={y} width={w} height={H} rx="2" />
{k === 'work' && <rect x={x + 3} y={y + 3} width={w - 6} height={H - 6} rx="1" class="sm-inner" />}
<text x={x + w / 2} y={y + H / 2 + 4} text-anchor="middle">
{name}
</text>
</g>
))
}
</g>
<g aria-hidden="true">
<text x="210" y="643" text-anchor="middle" class="sm-auto">any state → ERROR on ErrorFound</text>
{
E.map((e) => {
const [x, y] = e[5];
return e[3] ? (
<g class="sm-key">
<rect x={x - 7} y={y - 7} width="14" height="14" rx="2" />
<text x={x} y={y + 3.5} text-anchor="middle">
{e[3]}
</text>
</g>
) : (
<text x={x} y={y} class="sm-auto">
{e[2] === 'Auto' ? 'auto' : e[2]}
</text>
);
})
}
</g>
</svg>
</div>
<div class="sm-side">
<div class="sm-panel">
<div class="sm-ph">
<div class="sm-kind"><i></i><span data-kind>Idling state</span></div>
<p class="sm-name" data-name>IDLE</p>
</div>
<div class="sm-body">
<p class="sm-h">What happens</p>
<p data-does>{I.IDLE[1]}</p>
<p class="sm-h">Your code</p>
<p class="sm-hook" data-hook>—</p>
<p class="sm-h">Leave with</p>
<div class="sm-leave" data-leave></div>
</div>
<div class="sm-ctrl" data-ctrl></div>
<pre class="sm-log" aria-live="polite" data-log></pre>
</div>
<p class="sm-tip">
Select a state to read about it. The buttons and the keys <kbd>i</kbd>
<kbd>b</kbd>
<kbd>x</kbd>
<kbd>j</kbd>
<kbd>r</kbd>
<kbd>s</kbd>
<kbd>t</kbd>
<kbd>d</kbd>
<kbd>q</kbd> work like the interactive controller (<code>--control interactive</code>). <kbd>q</kbd> runs the shutdown sequence (Stop, ResetTask, ResetDevice, End) from RUNNING and from each idling state. <kbd>c</kbd> prints the current state.
</p>
</div>
</div>
<script>
for (const root of document.querySelectorAll<HTMLElement>('.fmq-sm')) {
const { N, E, I } = JSON.parse(root.dataset.sm!);
const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
const $ = <T extends HTMLElement>(s: string) => root.querySelector<T>(s)!;
const nodes = new Map<string, SVGGElement>();
root.querySelectorAll<SVGGElement>('[data-state]').forEach((g) => nodes.set(g.dataset.state!, g));
const edges = [...root.querySelectorAll<SVGPathElement>('[data-edge]')];
const log = $('[data-log]');
const ctrl = $('[data-ctrl]');
let cur = 'IDLE';
let sel = 'IDLE';
let busy = false;
let stopping = false;
let timer = 0;
// The key q of the controller runs the shutdown sequence from each state (Control.cxx RunShutdownSequence()).
// In this diagram, q works in RUNNING and in the idling states.
const SHUT: Record<string, string> = {
RUNNING: 'Stop',
READY: 'ResetTask',
'DEVICE READY': 'ResetDevice',
BOUND: 'ResetDevice',
INITIALIZED: 'ResetDevice',
IDLE: 'End',
};
const step = () => {
const e = outs(cur).find((x: string[]) => x[2] === SHUT[cur]);
if (!e) {
stopping = false;
render();
return;
}
timer = window.setTimeout(() => go(e[1]), reduce ? 250 : 650);
};
const shutdown = () => {
if (busy || stopping || !SHUT[cur]) return;
stopping = true;
render();
step();
};
const esc = (s: string) => s.replace(/[&<>]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;' })[c]!);
const write = (s: string, sev = 'STATE') => {
const div = document.createElement('div');
div.innerHTML = `<span class="${sev === 'STATE' ? 'st' : 'er'}">[${sev}]</span> ${esc(s)}`;
log.appendChild(div);
while (log.children.length > 12) log.firstChild!.remove();
log.scrollTop = log.scrollHeight;
};
const outs = (s: string) => E.filter((e: string[]) => e[0] === s);
const go = (to: string) => {
write(`${cur} ---> ${to}`);
cur = to;
sel = to;
const o = outs(cur);
busy = o.length === 1 && (o[0][2] === 'Auto' || o[0][2] === 'CompleteInit');
render();
if (busy) {
timer = window.setTimeout(() => {
busy = false;
go(o[0][1]);
}, reduce ? 250 : 950);
} else if (stopping) step();
};
const act = (e: string[]) => {
if (!busy && !stopping) go(e[1]);
};
const render = () => {
nodes.forEach((g, n) => {
g.classList.toggle('cur', n === cur);
g.classList.toggle('sel', n === sel && n !== cur);
g.setAttribute('aria-pressed', String(n === sel));
});
E.forEach((e: string[], i: number) => {
const live = e[0] === cur;
edges[i].classList.toggle('live', live);
edges[i].setAttribute('marker-end', live ? 'url(#sm-arr-on)' : 'url(#sm-arr)');
});
const [kind, does, hook] = I[sel];
$('[data-kind]').textContent = kind;
root.querySelector('.sm-kind i')!.className = N[sel][3] === 'work' ? 'work' : '';
$('[data-name]').textContent = sel;
$('[data-does]').textContent = does;
$('[data-hook]').textContent = hook;
const lv = outs(sel);
$('[data-leave]').innerHTML = lv.length
? lv.map((e: string[]) => `<span>${e[3] ? `<kbd>${e[3]}</kbd>` : ''}${e[2]} → ${e[1]}</span>`).join('')
: '<span>none</span>';
const lock = busy || stopping ? ' disabled' : '';
let h = `<span class="now">Device: <b>${cur}</b>${busy ? ' · working' : stopping ? ' · shutting down' : ''}</span>`;
outs(cur)
.filter((e: string[]) => e[2] !== 'Auto' && e[2] !== 'CompleteInit')
.forEach((e: string[]) => {
h += `<button class="sm-btn" type="button" data-e="${E.indexOf(e)}"${lock}><kbd>${e[3]}</kbd>${e[2]}</button>`;
});
if (cur !== 'IDLE' && SHUT[cur]) h += `<button class="sm-btn" type="button" data-q="1"${lock}><kbd>q</kbd>Shut down</button>`;
if (cur !== 'EXITING' && cur !== 'ERROR')
h += `<button class="sm-btn warn" type="button" data-err="1"${lock}>Throw in a hook</button>`;
else h += '<button class="sm-btn" type="button" data-reset="1">Start again</button>';
ctrl.innerHTML = h;
};
const reset = () => {
clearTimeout(timer);
busy = false;
stopping = false;
log.innerHTML = '';
cur = 'IDLE';
sel = 'IDLE';
write('Starting FairMQ state machine --> IDLE');
render();
};
ctrl.addEventListener('click', (ev) => {
const b = (ev.target as HTMLElement).closest('button');
if (!b) return;
if (b.dataset.e) act(E[Number(b.dataset.e)]);
else if (b.dataset.q) shutdown();
else if (b.dataset.err) {
clearTimeout(timer);
busy = false;
stopping = false;
// An exception in a hook sets ERROR without a [STATE] line (StateMachine.cxx ProcessWork()).
// The exception reaches DeviceRunner, which logs it.
cur = 'ERROR';
sel = 'ERROR';
render();
write('Uncaught exception reached the top of DeviceRunner: <what()>', 'ERROR');
} else if (b.dataset.reset) reset();
});
nodes.forEach((g, n) => {
g.addEventListener('click', () => {
sel = n;
render();
});
g.addEventListener('keydown', (ev) => {
if (ev.key === 'Enter' || ev.key === ' ') {
ev.preventDefault();
sel = n;
render();
}
});
});
root.addEventListener('keydown', (ev) => {
if ((ev.target as HTMLElement).closest('input,textarea') || ev.ctrlKey || ev.metaKey || ev.altKey) return;
const k = ev.key.toLowerCase();
if (k === 'c') {
write(cur);
return;
}
if (k === 'q') {
ev.preventDefault();
shutdown();
return;
}
const m = outs(cur).find((x: string[]) => x[3] === k);
if (m) {
ev.preventDefault();
act(m);
}
});
reset();
}
</script>
<style>
.fmq-sm {
display: grid;
grid-template-columns: minmax(0, 26rem) minmax(0, 1fr);
gap: 1.25rem;
align-items: start;
margin-block: 1.5rem;
}
@media (max-width: 52rem) {
.fmq-sm {
grid-template-columns: minmax(0, 1fr);
}
}
.sm-fig {
border: 1px solid var(--fmq-rule);
border-radius: 4px;
background: var(--fmq-paper);
padding: 0.5rem;
}
svg {
width: 100%;
height: auto;
display: block;
}
.sm-n {
cursor: pointer;
outline: none;
}
.sm-n rect {
fill: var(--fmq-paper);
stroke: var(--fmq-ink-3);
stroke-width: 1.2;
transition: fill 0.25s, stroke 0.25s;
}
.sm-n rect.sm-inner {
fill: none;
stroke-width: 1;
}
.sm-n text {
font: 600 10.5px var(--fmq-font-mono);
letter-spacing: 0.04em;
fill: var(--fmq-ink);
pointer-events: none;
}
.sm-n:hover rect:first-of-type,
.sm-n:focus-visible rect:first-of-type {
stroke: var(--fmq-link);
stroke-width: 2;
}
.sm-n.sel rect:first-of-type {
stroke: var(--fmq-ink);
stroke-width: 2.2;
}
.sm-n.cur rect:first-of-type {
fill: var(--fmq-saffron);
stroke: var(--fmq-bar);
}
.sm-n.cur rect.sm-inner {
stroke: var(--fmq-bar);
}
.sm-n.cur text {
fill: var(--fmq-on-saffron);
}
.sm-error rect:first-of-type {
stroke: var(--fmq-ruby);
}
.sm-end rect:first-of-type {
stroke-dasharray: 3 3;
}
.sm-e {
fill: none;
stroke: var(--fmq-rule-strong);
stroke-width: 1.2;
transition: stroke 0.25s;
}
.sm-e.live {
stroke: var(--fmq-ink);
stroke-width: 1.8;
stroke-dasharray: 5 4;
animation: smdash 1s linear infinite;
}
@keyframes smdash {
to {
stroke-dashoffset: -18;
}
}
.sm-ah {
fill: var(--fmq-rule-strong);
}
.sm-ah-on {
fill: var(--fmq-ink);
}
.sm-key rect {
fill: var(--fmq-paper-2);
stroke: var(--fmq-rule-strong);
}
.sm-key text {
font: 600 9.5px var(--fmq-font-mono);
fill: var(--fmq-ink);
}
.sm-auto {
font: italic 400 9.5px var(--fmq-font-mono);
fill: var(--fmq-ink-3);
}
.sm-panel {
border: 1px solid var(--fmq-rule);
border-radius: 4px;
background: var(--fmq-paper);
min-width: 0;
}
.sm-ph {
padding: 0.85rem 1rem 0.75rem;
border-bottom: 1px solid var(--fmq-rule);
}
.sm-kind {
font: 600 0.66rem/1.2 var(--fmq-font-body);
letter-spacing: 0.12em;
text-transform: uppercase;
color: var(--fmq-ink-3);
display: flex;
align-items: center;
gap: 0.5rem;
}
.sm-kind i {
width: 14px;
height: 10px;
border: 1px solid var(--fmq-ink-3);
}
.sm-kind i.work {
outline: 1px solid var(--fmq-ink-3);
outline-offset: 2px;
width: 10px;
height: 6px;
margin: 0 2px;
}
.sm-name {
font: 800 1.3rem/1.15 var(--fmq-font-body);
font-stretch: 108%;
margin: 0.35rem 0 0;
letter-spacing: -0.01em;
color: var(--fmq-ink);
}
.sm-body {
padding: 0.6rem 1rem 0.85rem;
font-size: 0.9rem;
}
.sm-body p {
margin: 0;
}
.sm-h {
font: 600 0.66rem/1.2 var(--fmq-font-body);
letter-spacing: 0.12em;
text-transform: uppercase;
color: var(--fmq-ink-3);
margin: 0.75rem 0 0.25rem !important;
}
.sm-hook {
font: 600 0.8125rem/1.5 var(--fmq-font-mono);
color: var(--fmq-accent-ink);
}
.sm-leave {
display: flex;
flex-wrap: wrap;
gap: 0.4rem;
}
.sm-leave :global(span) {
font: 500 0.75rem/1 var(--fmq-font-mono);
border: 1px solid var(--fmq-rule);
border-radius: 3px;
padding: 0.3rem 0.45rem;
color: var(--fmq-ink-2);
display: inline-flex;
gap: 0.35rem;
align-items: center;
}
.sm-ctrl {
padding: 0.75rem 1rem;
border-top: 1px solid var(--fmq-rule);
background: var(--fmq-paper-2);
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
align-items: center;
}
.sm-ctrl :global(.now) {
font: 600 0.75rem/1.2 var(--fmq-font-mono);
color: var(--fmq-ink-2);
flex-basis: 100%;
}
.sm-ctrl :global(.now b) {
color: var(--fmq-ink);
}
.sm-ctrl :global(.sm-btn) {
display: inline-flex;
align-items: center;
gap: 0.45rem;
font: 500 0.8125rem/1 var(--fmq-font-body);
padding: 0.45rem 0.6rem;
border: 1px solid var(--fmq-rule-strong);
border-radius: 4px;
background: var(--fmq-paper);
color: var(--fmq-ink);
cursor: pointer;
}
.sm-ctrl :global(.sm-btn:hover) {
border-color: var(--fmq-ink-3);
}
.sm-ctrl :global(.sm-btn:disabled) {
opacity: 0.5;
cursor: default;
}
.sm-ctrl :global(.sm-btn.warn) {
color: var(--fmq-ruby);
}
.fmq-sm :global(kbd) {
display: inline-grid;
place-items: center;
min-width: 18px;
height: 18px;
font: 600 0.65rem/1 var(--fmq-font-mono);
border: 1px solid var(--fmq-rule-strong);
border-bottom-width: 2px;
border-radius: 3px;
background: var(--fmq-paper-2);
color: var(--fmq-ink);
padding: 0 4px;
}
.sm-log {
margin: 0;
padding: 0.6rem 0.75rem;
background: var(--fmq-code-bg);
color: var(--fmq-code-ink);
font: 400 0.75rem/1.6 var(--fmq-font-mono);
border-radius: 0 0 4px 4px;
height: 7.4rem;
overflow: auto;
white-space: pre-wrap;
overflow-wrap: anywhere;
border: 0;
}
.sm-log :global(.st) {
color: var(--fmq-c-kw);
}
.sm-log :global(.er) {
color: var(--fmq-c-num);
}
.sm-tip {
font-size: 0.8125rem;
color: var(--fmq-ink-3);
margin: 0.5rem 0.1rem 0;
line-height: 1.9;
}
.sm-tip code {
font-size: 0.8em;
}
</style>

View File

@@ -0,0 +1,348 @@
---
// A topology like example 1-n-1, animated: a sampler, three processors and a sink.
// (The start script of example 1-n-1 runs two processors.)
// The switch shows what the shmem transport changes: only a MetaHeader goes through each socket.
---
<div class="fmq-topo not-content">
<div class="tp-head">
<div class="tp-switch" role="group" aria-label="Transport">
<button type="button" data-mode="zeromq" aria-pressed="true">zeromq</button>
<button type="button" data-mode="shmem" aria-pressed="false">shmem</button>
</div>
<span>1 sampler · 3 processors · 1 sink</span>
</div>
<svg class="tp" viewBox="0 0 560 296" role="img" aria-label="A sampler sends messages round-robin to three processors. The processors send them to a sink.">
<g class="tp-edges">
<path d="M130 140 H178 V62 H225"></path><path d="M130 140 H225"></path><path d="M130 140 H178 V218 H225"></path>
<path d="M335 62 H382 V140 H430"></path><path d="M335 140 H430"></path><path d="M335 218 H382 V140 H430"></path>
</g>
<g class="tp-seg">
<rect x="20" y="260" width="520" height="28"></rect>
<text x="22" y="254" class="tp-addr">shared memory segment · session "default"</text>
</g>
<g class="tp-blocks"></g>
<g class="tp-dev">
<rect x="20" y="112" width="110" height="56"></rect>
<rect class="tp-port" x="126" y="136" width="8" height="8"></rect>
<text x="32" y="136" class="tp-name">sampler</text>
<text x="32" y="154" class="tp-sub">push · bind</text>
</g>
<g class="tp-dev">
{
[40, 118, 196].map((y, i) => (
<>
<rect x="225" y={y} width="110" height="44" class="tp-proc" data-p={i} />
<rect class="tp-port" x="221" y={y + 18} width="8" height="8" />
<rect class="tp-port" x="331" y={y + 18} width="8" height="8" />
<text x="238" y={y + 20} class="tp-name">
processor
</text>
<text x="238" y={y + 35} class="tp-sub">
pull → push
</text>
</>
))
}
</g>
<g class="tp-dev">
<rect x="430" y="112" width="110" height="56"></rect>
<rect class="tp-port" x="426" y="136" width="8" height="8"></rect>
<text x="442" y="136" class="tp-name">sink</text>
<text x="442" y="154" class="tp-sub">pull · bind</text>
</g>
<text x="22" y="104" class="tp-addr">tcp://*:5555</text>
<text x="538" y="104" text-anchor="end" class="tp-addr">tcp://*:5556</text>
<g class="tp-parts"></g>
</svg>
<p class="tp-cap" aria-live="polite">zeromq: the payload goes through each socket.</p>
</div>
<script>
for (const root of document.querySelectorAll<HTMLElement>('.fmq-topo')) {
const svg = root.querySelector<SVGSVGElement>('svg.tp')!;
const NS = 'http://www.w3.org/2000/svg';
const parts = svg.querySelector('.tp-parts')!;
const blocks = svg.querySelector('.tp-blocks')!;
const cap = root.querySelector('.tp-cap')!;
const buttons = [...root.querySelectorAll<HTMLButtonElement>('[data-mode]')];
const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
// A route: segments with start time and duration. The hop through the processor is slow.
const mk = (pts: number[][], slow: number) => {
const segs: { x1: number; y1: number; x2: number; y2: number; t0: number; d: number; slow: boolean }[] = [];
let T = 0;
for (let i = 1; i < pts.length; i++) {
const [x1, y1] = pts[i - 1];
const [x2, y2] = pts[i];
const l = Math.hypot(x2 - x1, y2 - y1);
if (l < 0.5) continue;
const d = l / (i - 1 === slow ? 58 : 170);
segs.push({ x1, y1, x2, y2, t0: T, d, slow: i - 1 === slow });
T += d;
}
return { segs, T };
};
const routes = [62, 140, 218].map((py) =>
mk(
[
[130, 140],
[178, 140],
[178, py],
[225, py],
[335, py],
[382, py],
[382, 140],
[430, 140],
],
3
)
);
type Route = (typeof routes)[number];
// Position at time t, and whether the message is inside the processor.
const at = (r: Route, t: number): [number, number, boolean] => {
for (const s of r.segs) {
if (t <= s.t0 + s.d) {
const u = (t - s.t0) / s.d;
return [s.x1 + (s.x2 - s.x1) * u, s.y1 + (s.y2 - s.y1) * u, s.slow];
}
}
const s = r.segs[r.segs.length - 1];
return [s.x2, s.y2, false];
};
const procs = [...svg.querySelectorAll<SVGRectElement>('.tp-proc')];
const busy = [0, 0, 0];
type Part = { r: Route; p: number; t: number; e: SVGRectElement; s: number; blk: SVGRectElement | null; slot: number; inside: boolean };
let mode = 'zeromq';
let list: Part[] = [];
let last = 0;
let acc = 0;
let rr = 0;
let running = false;
let raf = 0;
const slots = new Array(16).fill(false);
const rect = (a: Record<string, string | number>, p: Element) => {
const e = document.createElementNS(NS, 'rect');
for (const k in a) e.setAttribute(k, String(a[k]));
p.appendChild(e);
return e;
};
const setInside = (p: Part, inside: boolean) => {
if (p.inside === inside) return;
p.inside = inside;
busy[p.p] += inside ? 1 : -1;
procs[p.p].classList.toggle('busy', busy[p.p] > 0);
p.e.style.visibility = inside ? 'hidden' : '';
};
const place = (p: Part) => {
const [x, y, inside] = at(p.r, p.t);
p.e.setAttribute('x', (x - p.s / 2).toFixed(1));
p.e.setAttribute('y', (y - p.s / 2).toFixed(1));
setInside(p, inside);
};
const spawn = (t0 = 0) => {
const r = routes[rr];
const pi = rr;
rr = (rr + 1) % 3;
const shm = mode === 'shmem';
const s = shm ? 6 : 10;
let blk: SVGRectElement | null = null;
let slot = -1;
if (shm) {
slot = slots.indexOf(false);
if (slot < 0) return;
slots[slot] = true;
blk = rect({ x: 28 + slot * 32, y: 267, width: 24, height: 14, class: 'tp-blk' }, blocks);
}
const e = rect({ width: s, height: s, class: shm ? 'tp-meta' : 'tp-pay' }, parts);
const p: Part = { r, p: pi, t: t0, e, s, blk, slot, inside: false };
place(p);
list.push(p);
};
const clear = () => {
list.forEach((p) => {
setInside(p, false);
p.e.remove();
p.blk?.remove();
});
list = [];
slots.fill(false);
blocks.replaceChildren();
};
const frame = (ts: number) => {
if (!running) return;
const dt = Math.min(0.05, (ts - (last || ts)) / 1000);
last = ts;
acc += dt;
if (acc > 0.55) {
acc = 0;
spawn();
}
list.forEach((p) => {
p.t += dt;
place(p);
});
list = list.filter((p) => {
if (p.t < p.r.T) return true;
setInside(p, false);
p.e.remove();
if (p.blk) {
const b = p.blk;
const sl = p.slot;
b.style.opacity = '0';
setTimeout(() => {
b.remove();
slots[sl] = false;
}, 420);
}
return false;
});
raf = requestAnimationFrame(frame);
};
const still = () => {
clear();
[0.5, 1.4, 2.2, 2.9, 3.5, 1.0].forEach((t) => spawn(t));
};
const setMode = (m: string) => {
mode = m;
svg.classList.toggle('shm', m === 'shmem');
buttons.forEach((b) => b.setAttribute('aria-pressed', String(b.dataset.mode === m)));
clear();
cap.textContent =
m === 'shmem'
? 'shmem: the payload stays in the shared memory segment. Only a MetaHeader of 40 bytes goes through each socket.'
: 'zeromq: the payload goes through each socket.';
if (reduce || !running) still();
};
buttons.forEach((b) => b.addEventListener('click', () => setMode(b.dataset.mode!)));
still();
if (!reduce && 'IntersectionObserver' in window) {
new IntersectionObserver(
(es) => {
for (const e of es) {
if (e.isIntersecting && !running) {
clear();
running = true;
last = 0;
raf = requestAnimationFrame(frame);
} else if (!e.isIntersecting && running) {
running = false;
cancelAnimationFrame(raf);
}
}
},
{ threshold: 0.2 }
).observe(svg);
}
}
</script>
<style>
.fmq-topo {
min-width: 0;
border: 1px solid var(--fmq-rule);
background: var(--fmq-paper);
border-radius: 6px;
padding: 0.75rem 0.75rem 0.6rem;
}
.tp-head {
display: flex;
justify-content: space-between;
align-items: center;
gap: 0.6rem;
flex-wrap: wrap;
}
.tp-head span {
font-size: 0.78rem;
color: var(--fmq-ink-3);
}
.tp-switch {
display: inline-flex;
border: 1px solid var(--fmq-rule-strong);
border-radius: 4px;
overflow: hidden;
}
.tp-switch button {
font: 600 0.78rem/1 var(--fmq-font-mono);
border: 0;
background: var(--fmq-paper);
color: var(--fmq-ink-2);
padding: 0.5rem 0.9rem;
cursor: pointer;
}
.tp-switch button + button {
border-inline-start: 1px solid var(--fmq-rule-strong);
}
.tp-switch button[aria-pressed='true'] {
background: var(--fmq-ink);
color: var(--fmq-paper);
}
svg {
width: 100%;
height: auto;
display: block;
margin-top: 0.4rem;
}
.tp-edges path {
fill: none;
stroke: var(--fmq-rule-strong);
stroke-width: 1.4;
}
.tp-dev rect {
fill: var(--fmq-paper);
stroke: var(--fmq-ink-2);
stroke-width: 1.2;
}
.tp-dev rect.tp-port {
fill: var(--fmq-ink-2);
}
.tp-dev rect.tp-proc {
transition:
fill 0.2s,
stroke 0.2s;
}
.tp-dev rect.tp-proc:global(.busy) {
fill: var(--fmq-saffron-tint);
stroke: var(--fmq-bar);
}
.tp-name {
font: 600 12.5px var(--fmq-font-mono);
fill: var(--fmq-ink);
}
.tp-sub,
.tp-addr {
font: 400 10.5px var(--fmq-font-mono);
fill: var(--fmq-ink-3);
}
.tp-seg {
opacity: 0;
transition: opacity 0.4s;
}
.tp-seg rect {
fill: var(--fmq-paper-2);
stroke: var(--fmq-rule-strong);
stroke-dasharray: 3 3;
}
svg.shm .tp-seg {
opacity: 1;
}
.tp-parts :global(.tp-pay) {
fill: var(--fmq-saffron);
stroke: var(--fmq-bar);
stroke-width: 1;
}
.tp-parts :global(.tp-meta) {
fill: var(--fmq-sky);
}
.tp-blocks :global(.tp-blk) {
fill: var(--fmq-saffron);
stroke: var(--fmq-bar);
stroke-width: 1;
transition: opacity 0.4s;
}
.tp-cap {
margin: 0.4rem 0.15rem 0;
font-size: 0.85rem;
color: var(--fmq-ink-2);
min-height: 2.8em;
}
</style>

View File

@@ -0,0 +1,274 @@
---
// One message through the shmem transport, step by step.
// Facts: fairmq/shmem/Common.h (MetaHeader, MakeShmName, makeShmIdStr), Socket.h (Send, Receive),
// Message.h (Deallocate), plugins/config/Config.cxx (--shm-segment-size default 2 GiB).
import Explainer from './Explainer.astro';
const steps = [
{
cap: 'Two devices run on one host. Both map the same managed segment. FairMQ makes the name of the segment from the session name and the user ID.',
code: '--transport shmem --session default',
},
{
cap: 'The sampler asks for a message of 1 MiB. The transport allocates a block in the segment.',
code: 'auto msg = NewMessage(1 << 20);',
set: { a: 'NewMessage(1 << 20)' },
},
{
cap: 'The sampler writes the payload into the block. The payload stays in the segment.',
code: 'std::memcpy(msg->GetData(), src, msg->GetSize());',
set: { a: 'write the payload' },
},
{
cap: 'Send() puts only a MetaHeader of 40 bytes into a ZeroMQ message. It holds the size, the hint, the handle of the block, the handle of the reference count of a copied region block, the IDs of the region and the segment, and a flag for segment or region. The message of the sampler no longer owns the block.',
code: 'Send(msg, "data");',
set: { a: 'Send(msg, "data")' },
},
{
cap: 'The sink receives the MetaHeader. At the first GetData(), it changes the handle into an address in its own mapping of the segment.',
code: 'Receive(msg, "data");',
set: { b: 'Receive(msg, "data")' },
},
{
cap: 'The sink reads the payload in place. The transport copied no byte of the payload.',
code: 'auto* data = static_cast<char*>(msg->GetData());',
set: { b: 'msg->GetData()' },
},
{
cap: 'The message of the sink goes out of scope. The transport gives the block back to the segment.',
code: '} // msg is destroyed: the block is free again',
set: { b: '~Message()' },
},
{
cap: 'Compare: with the zeromq transport, the full payload goes through the socket on each hop.',
code: '--transport zeromq',
set: { a: 'Send(msg, "data")', b: 'Receive(msg, "data")' },
},
];
---
<Explainer title="One message, no copy" meta="sampler → sink · same host" steps={steps}>
<svg class="zc" data-stage viewBox="0 0 720 318" role="img" aria-label="Zero-copy transfer with the shmem transport">
<defs>
<pattern id="zc-cells" width="16" height="76" patternUnits="userSpaceOnUse"><line x1="0.5" y1="0" x2="0.5" y2="76" class="cell"></line></pattern>
<pattern id="zc-stripes" width="8" height="8" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"><rect width="3" height="8" class="stripe"></rect></pattern>
<marker id="zc-arr" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"
><path d="M0 0L10 5L0 10z" class="arrhead"></path></marker
>
</defs>
<line x1="240" y1="64" x2="480" y2="64" class="chan"></line>
<text x="360" y="88" text-anchor="middle" class="sub">channel "data" · push → pull</text>
<g class="maps">
<line x1="140" y1="116" x2="140" y2="204" class="map"></line>
<line x1="580" y1="116" x2="580" y2="204" class="map"></line>
<text x="150" y="166" class="sub">maps</text>
<text x="590" y="166" class="sub">maps</text>
</g>
<g class="seg">
<rect x="40" y="204" width="640" height="76" rx="2" class="segbox"></rect>
<rect x="40" y="204" width="640" height="76" fill="url(#zc-cells)"></rect>
<text x="40" y="300" class="sub">/dev/shm/fmq_&lt;shmId&gt;_m_0</text>
<text x="680" y="300" text-anchor="end" class="sub">managed segment · 2 GiB</text>
</g>
<g class="block">
<rect x="300" y="222" width="140" height="40" class="blk"></rect>
<rect class="fill" x="300" y="222" width="140" height="40" fill="url(#zc-stripes)"></rect>
<text class="blklabel" x="370" y="247" text-anchor="middle">1 MiB payload</text>
</g>
<rect class="blkline" x="298.5" y="220.5" width="143" height="43"></rect>
<text class="read sub mint" x="370" y="214" text-anchor="middle">read in place</text>
<text class="freed sub" x="370" y="247" text-anchor="middle">the block is free again</text>
<path class="hdl" d="M560 116 C 548 168, 480 190, 446 222" marker-end="url(#zc-arr)"></path>
<text class="hdllabel sub sky" x="470" y="184" text-anchor="end">handle → address</text>
<g class="proc">
<rect x="40" y="28" width="200" height="88" rx="3"></rect>
<text x="58" y="56" class="name">sampler</text>
<text x="58" y="76" class="sub">process A</text>
<text x="58" y="100" class="code" data-slot="a"></text>
</g>
<g class="proc">
<rect x="480" y="28" width="200" height="88" rx="3"></rect>
<text x="498" y="56" class="name">sink</text>
<text x="498" y="76" class="sub">process B</text>
<text x="498" y="100" class="code" data-slot="b"></text>
</g>
<g class="meta">
<rect x="232" y="56" width="16" height="16" class="metabox"></rect>
<text class="metalabel sub sky" x="240" y="46" text-anchor="middle">MetaHeader · 40 B</text>
</g>
<g class="zmq">
<rect x="236" y="50" width="56" height="28" class="blk"></rect>
<text x="264" y="69" text-anchor="middle" class="blklabel">1 MiB</text>
</g>
</svg>
</Explainer>
<style>
.name {
fill: var(--fmq-stage-ink);
font-size: 16px;
font-weight: 700;
}
.sub {
fill: var(--fmq-stage-dim);
font-size: 11.5px;
}
.code {
fill: var(--fmq-saffron);
font-size: 11.5px;
font-weight: 600;
}
.proc rect {
fill: var(--fmq-stage-2);
stroke: var(--fmq-stage-line);
stroke-width: 1.2;
}
.chan {
stroke: var(--fmq-stage-line);
stroke-width: 1.5;
}
.map {
stroke: var(--fmq-stage-line);
stroke-dasharray: 4 4;
stroke-width: 1.2;
}
.segbox {
fill: var(--fmq-stage-2);
stroke: var(--fmq-stage-line);
}
.cell {
stroke: var(--fmq-stage-cell);
stroke-width: 1;
}
.blk {
fill: var(--fmq-saffron);
}
.stripe {
fill: rgb(26 26 26 / 0.22);
}
.blklabel {
fill: var(--fmq-on-saffron);
font-size: 12px;
font-weight: 700;
}
.metabox {
fill: var(--fmq-sky-bright);
}
.hdl {
fill: none;
stroke: var(--fmq-sky-bright);
stroke-width: 1.6;
stroke-dasharray: 5 4;
}
.arrhead,
.sky {
fill: var(--fmq-sky-bright);
}
.mint {
fill: var(--fmq-mint);
font-weight: 700;
}
.block {
transform-box: fill-box;
transform-origin: left center;
transform: scaleX(0);
transition:
transform 0.9s cubic-bezier(0.2, 0, 0.1, 1),
opacity 0.7s;
}
.zc.r2 .block {
transform: scaleX(1);
}
.zc.r7 .block {
opacity: 0;
}
.fill,
.blklabel {
opacity: 0;
transition: opacity 0.8s;
}
.zc.r3 .fill,
.zc.r3 .blklabel,
.zmq .blklabel {
opacity: 1;
}
.blkline {
fill: none;
stroke: var(--fmq-mint);
stroke-width: 3;
opacity: 0;
transition: opacity 0.5s;
}
.zc.now6 .blkline {
opacity: 1;
}
.meta {
opacity: 0;
transform: translate(0, 0);
transition:
transform 1.5s cubic-bezier(0.45, 0, 0.2, 1),
opacity 0.35s;
}
.zc.r4 .meta {
opacity: 1;
transform: translate(112px, 0);
}
.zc.r5 .meta {
transform: translate(216px, 0);
}
.metalabel {
transition: opacity 0.4s;
}
.zc.r5 .metalabel {
opacity: 0;
}
.zc.r6 .meta {
opacity: 0;
}
.hdl,
.hdllabel {
opacity: 0;
transition: opacity 0.6s;
}
.zc.r5 .hdl,
.zc.r5 .hdllabel {
opacity: 1;
}
.zc.r7 .hdl,
.zc.r7 .hdllabel {
opacity: 0;
}
.read,
.freed {
opacity: 0;
transition: opacity 0.5s;
}
.zc.now6 .read,
.zc.now7 .freed {
opacity: 1;
}
.zmq {
opacity: 0;
transform: translate(0, 0);
transition:
transform 2.4s cubic-bezier(0.45, 0, 0.2, 1),
opacity 0.35s;
}
.zc.now8 .zmq {
opacity: 1;
transform: translate(176px, 0);
}
.maps,
.seg {
transition: opacity 0.5s;
}
.zc.now8 .maps,
.zc.now8 .seg {
opacity: 0.22;
}
@media (prefers-reduced-motion: reduce) {
.zc * {
transition: none !important;
}
}
</style>

View File

@@ -0,0 +1,94 @@
---
// "A complete device": the smallest program that runs with runDevice.h, and its log.
import { Code } from '@astrojs/starlight/components';
const base = import.meta.env.BASE_URL.replace(/\/$/, '');
const device = `#include <fairmq/Device.h>
#include <fairmq/runDevice.h>
struct Sampler : fair::mq::Device
{
bool ConditionalRun() override
{
auto msg = NewSimpleMessage("Hello");
LOG(info) << "Sending \\"Hello\\"";
return Send(msg, "data") >= 0; // false ends RUNNING
}
};
void addCustomOptions(boost::program_options::options_description&) {}
std::unique_ptr<fair::mq::Device> getDevice(fair::mq::ProgOptions&)
{
return std::make_unique<Sampler>();
}`;
const run = `fairmq-ex-1-1-sampler --id sampler1 --rate 1 \\
--channel-config "name=data,type=push,method=bind,address=tcp://*:5555,rateLogging=0"`;
const log = `[10:42:07][STATE] IDLE ---> INITIALIZING DEVICE
...
[10:42:07][STATE] READY ---> RUNNING
[10:42:07][INFO] fair::mq::Device running...
[10:42:07][INFO] Sending "Hello"
[10:42:08][INFO] Sending "Hello"`;
---
<section class="fmq-homecode not-content" aria-labelledby="home-code">
<div class="hc-text">
<h2 id="home-code">A complete device</h2>
<p>Derive from <code>fair::mq::Device</code> and override one hook. <code>runDevice.h</code> adds the <code>main()</code> function. It parses the command line, loads the plugins and runs the state machine.</p>
<p>In the state RUNNING, the device calls <code>ConditionalRun()</code> in a loop, at the rate of <code>--rate</code>. Each call sends one message. When the function returns <code>false</code>, the device leaves the state RUNNING.</p>
<a href={`${base}/start/first-device/`}>Your first device →</a>
</div>
<div class="hc-code">
<Code code={device} lang="cpp" title="sampler.cxx" />
<Code code={`$ ${run}\n${log}`} lang="txt" frame="terminal" title="Run example 1-1" />
</div>
</section>
<style>
.fmq-homecode {
display: grid;
grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
gap: 2rem;
margin-block: 0 2rem;
}
@media (max-width: 60rem) {
.fmq-homecode {
grid-template-columns: minmax(0, 1fr);
gap: 1rem;
}
}
h2 {
font-size: 1.5rem;
font-weight: 800;
font-stretch: 112%;
line-height: 1.15;
margin: 0 0 0.75rem;
color: var(--fmq-ink);
}
.hc-text p {
margin: 0 0 0.9rem;
color: var(--fmq-ink-2);
max-width: 44ch;
}
.hc-text code {
font-size: 0.85em;
background: var(--fmq-paper-3);
border: 1px solid var(--fmq-rule);
border-radius: 3px;
padding: 0.05em 0.3em;
}
.hc-text a {
font-weight: 600;
color: var(--fmq-link);
text-decoration: none;
}
.hc-code {
min-width: 0;
display: flex;
flex-direction: column;
gap: 0.9rem;
}
.hc-code :global(.expressive-code) {
margin: 0 !important;
}
</style>

View File

@@ -0,0 +1,96 @@
---
// Three ways into the docs, below the hero of the home page.
const base = import.meta.env.BASE_URL.replace(/\/$/, '');
const cols = [
{
label: 'Start',
links: [
['Install', '/start/install/'],
['Your first device', '/start/first-device/'],
['Use FairMQ in a CMake project', '/start/cmake/'],
],
},
{
label: 'Understand',
links: [
['Device states', '/concepts/states/'],
['Channels and sockets', '/concepts/channels/'],
['How shared memory works', '/shmem/how-it-works/'],
],
},
{
label: 'Operate',
links: [
['Command-line options', '/reference/options/'],
['Sessions and segments', '/shmem/sessions/'],
['Built-in devices', '/tools/builtin-devices/'],
],
},
];
---
<nav class="fmq-paths not-content" aria-label="Ways into the documentation">
{
cols.map((c) => (
<div>
<p class="fmq-eyebrow">{c.label}</p>
{c.links.map(([t, l]) => (
<a href={base + l}>{t}</a>
))}
</div>
))
}
</nav>
<style>
.fmq-paths {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
border-top: 1px solid var(--fmq-rule);
border-bottom: 1px solid var(--fmq-rule);
margin-block: 0 2.5rem;
}
.fmq-paths > div {
padding: 1.4rem 1.5rem;
border-inline-end: 1px solid var(--fmq-rule);
display: flex;
flex-direction: column;
gap: 0.45rem;
min-width: 0;
}
.fmq-paths > div:first-child {
padding-inline-start: 0;
}
.fmq-paths > div:last-child {
border-inline-end: 0;
}
.fmq-paths .fmq-eyebrow {
margin-bottom: 0.35rem;
}
.fmq-paths a {
color: var(--fmq-ink);
text-decoration: none;
font-weight: 500;
font-size: 0.975rem;
}
.fmq-paths a::after {
content: ' →';
color: var(--fmq-ink-3);
}
.fmq-paths a:hover {
color: var(--fmq-link);
}
@media (max-width: 48rem) {
.fmq-paths {
grid-template-columns: minmax(0, 1fr);
}
.fmq-paths > div {
padding-inline: 0;
border-inline-end: 0;
border-bottom: 1px solid var(--fmq-rule);
}
.fmq-paths > div:last-child {
border-bottom: 0;
}
}
</style>

View File

@@ -0,0 +1,61 @@
---
// Page footer: edit link, last change, pagination, and the site line.
import EditLink from '@astrojs/starlight/components/EditLink.astro';
import LastUpdated from '@astrojs/starlight/components/LastUpdated.astro';
import Pagination from '@astrojs/starlight/components/Pagination.astro';
import { build } from 'virtual:fairmq/data';
---
<footer class="fmq-footer">
<Pagination />
<div class="meta">
<EditLink />
<LastUpdated />
<p>
Built from <a href={`${build.repo}/commit/${build.commit}`}>{build.branch} @ {build.commitShort}</a>
</p>
</div>
<div class="site">
<span>FairMQ · LGPL-3.0-only · GSI Helmholtzzentrum für Schwerionenforschung GmbH</span>
<a href={build.repo}>github.com/FairRootGroup/FairMQ</a>
</div>
</footer>
<style>
.fmq-footer {
display: flex;
flex-direction: column;
gap: 1.5rem;
margin-top: 3rem;
}
.meta {
display: flex;
flex-wrap: wrap;
gap: 0.5rem 1.75rem;
align-items: center;
border-top: 1px solid var(--fmq-rule);
padding-top: 0.9rem;
font-size: 0.8125rem;
color: var(--fmq-ink-3);
}
.meta :global(p) {
margin: 0;
}
.meta a,
.site a {
color: var(--fmq-ink-3);
}
.meta a:hover,
.site a:hover {
color: var(--fmq-ink);
}
.site {
display: flex;
flex-wrap: wrap;
gap: 0.5rem 1.5rem;
justify-content: space-between;
font-size: 0.8125rem;
color: var(--fmq-ink-3);
padding-bottom: 1rem;
}
</style>

View File

@@ -0,0 +1,174 @@
---
// Site header: logo and version, search, main sections, GitHub and theme.
import Search from '@astrojs/starlight/components/Search.astro';
import SocialIcons from '@astrojs/starlight/components/SocialIcons.astro';
import ThemeSelect from '@astrojs/starlight/components/ThemeSelect.astro';
import { build } from 'virtual:fairmq/data';
import Glyph from '../Glyph.astro';
import { sections } from '../../lib/nav';
const base = import.meta.env.BASE_URL.replace(/\/$/, '');
const path = Astro.url.pathname;
---
<div class="fmq-header">
<div class="fmq-brand">
<a class="fmq-logo" href={`${base}/`}>
<Glyph />
<span translate="no">FairMQ</span>
</a>
<a
class="fmq-ver"
href={`${base}/project/release-notes/`}
title={build.unreleased ? `Built from ${build.branch} @ ${build.commitShort}` : `Release ${build.release}`}
>
{build.label}
{build.unreleased && <b>dev</b>}
</a>
</div>
<div class="fmq-search print:hidden"><Search /></div>
<nav class="fmq-nav sl-hidden md:sl-flex print:hidden" aria-label="Sections">
{
sections.map((s) => (
<a href={`${base}${s.href}`} aria-current={s.match(path, base) ? 'page' : undefined}>
{s.label}
</a>
))
}
</nav>
<div class="fmq-right sl-hidden md:sl-flex print:hidden">
<div class="sl-flex fmq-social"><SocialIcons /></div>
<ThemeSelect />
</div>
</div>
<style>
.fmq-header {
display: flex;
align-items: center;
gap: 1rem;
height: 100%;
}
.fmq-brand {
display: flex;
align-items: center;
gap: 0.6rem;
min-width: 0;
flex: none;
}
.fmq-logo {
display: flex;
align-items: center;
gap: 0.5rem;
font: 800 1.125rem/1 var(--fmq-font-body);
font-stretch: 114%;
letter-spacing: -0.01em;
color: var(--fmq-ink);
text-decoration: none;
white-space: nowrap;
}
.fmq-ver {
display: none;
align-items: center;
gap: 0.35rem;
font: 500 0.75rem/1 var(--fmq-font-mono);
border: 1px solid var(--fmq-rule-strong);
border-radius: 3px;
padding: 0.3rem 0.45rem;
color: var(--fmq-ink-2);
text-decoration: none;
white-space: nowrap;
}
.fmq-ver b {
font-weight: 500;
color: var(--fmq-accent-ink);
}
.fmq-ver:hover {
border-color: var(--fmq-ink-3);
color: var(--fmq-ink);
}
.fmq-search {
display: flex;
flex: 1 1 auto;
justify-content: flex-end;
min-width: 0;
}
.fmq-nav {
gap: 1.25rem;
align-self: stretch;
align-items: stretch;
font-size: 0.875rem;
font-weight: 500;
}
.fmq-nav a {
display: flex;
align-items: center;
color: var(--fmq-ink-2);
text-decoration: none;
border-bottom: 2px solid transparent;
margin-bottom: calc(-1 * var(--sl-nav-pad-y) - 1px);
margin-top: calc(-1 * var(--sl-nav-pad-y));
white-space: nowrap;
}
.fmq-nav a:hover {
color: var(--fmq-ink);
}
.fmq-nav a[aria-current='page'] {
color: var(--fmq-ink);
border-bottom-color: var(--fmq-saffron);
}
.fmq-right {
gap: 1rem;
align-items: center;
}
.fmq-social {
gap: 1rem;
align-items: center;
}
.fmq-social::after {
content: '';
height: 1.5rem;
border-inline-end: 1px solid var(--fmq-rule);
}
/* The search button: a quiet field on wide screens, an icon on phones. */
.fmq-search :global(button[data-open-modal]) {
border-radius: 4px;
border-color: var(--fmq-rule);
background: var(--fmq-paper-2);
color: var(--fmq-ink-3);
font-size: 0.875rem;
}
.fmq-search :global(button[data-open-modal]:hover) {
border-color: var(--fmq-ink-3);
color: var(--fmq-ink);
}
.fmq-search :global(button[data-open-modal] kbd) {
font-family: var(--fmq-font-mono);
background: var(--fmq-paper);
border-radius: 3px;
}
@media (min-width: 30rem) {
.fmq-ver {
display: inline-flex;
}
}
@media (min-width: 50rem) {
.fmq-header {
gap: 1.5rem;
}
.fmq-search {
justify-content: flex-start;
flex: 0 1 22rem;
margin-inline-start: 0.5rem;
}
.fmq-search :global(site-search),
.fmq-search :global(button[data-open-modal]) {
width: 100%;
}
.fmq-nav {
margin-inline-start: auto;
}
}
</style>

View File

@@ -0,0 +1,121 @@
---
// The hero of the home page: the claim, two actions, the install command and the topology.
import Topology from '../diagrams/Topology.astro';
import CopyButton from '../CopyButton.astro';
const { data } = Astro.locals.starlightRoute.entry;
const { title = data.title, tagline, actions = [] } = data.hero ?? {};
const base = import.meta.env.BASE_URL.replace(/\/$/, '');
const href = (link: string) => (link.startsWith('/') && !link.startsWith(base + '/') ? base + link : link);
const install = 'spack install fairmq';
---
<div class="fmq-hero">
<div class="h-text">
<p class="fmq-eyebrow">C++17 message queuing · LGPL-3.0</p>
<h1 id="_top" data-page-title>{title}</h1>
{tagline && <p class="h-lead" set:html={tagline} />}
<div class="h-cta">
{
actions.map((a) => (
<a class:list={['h-btn', { pri: a.variant === 'primary' }]} href={href(a.link)}>
{a.text}
</a>
))
}
</div>
<div class="h-install">
<span aria-hidden="true">$</span>
<code>{install}</code>
<CopyButton text={install} label="Copy the install command" />
</div>
</div>
<Topology />
</div>
<style>
.fmq-hero {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
gap: 2.25rem;
align-items: center;
padding-block: 1.5rem 2.5rem;
}
@media (max-width: 60rem) {
.fmq-hero {
grid-template-columns: minmax(0, 1fr);
gap: 1.75rem;
padding-block: 0.5rem 1.75rem;
}
}
h1 {
font-size: clamp(2.1rem, 1.4rem + 2.4vw, 3.05rem);
line-height: 1.03;
font-weight: 800;
font-stretch: 118%;
letter-spacing: -0.026em;
margin: 0.6rem 0 1rem;
text-wrap: balance;
color: var(--fmq-ink);
}
.h-lead {
font-size: 1.125rem;
line-height: 1.55;
color: var(--fmq-ink-2);
margin: 0 0 1.5rem;
max-width: 46ch;
}
.h-cta {
display: flex;
flex-wrap: wrap;
gap: 0.6rem;
}
.h-btn {
display: inline-flex;
align-items: center;
font: 600 0.9375rem/1 var(--fmq-font-body);
padding: 0.75rem 1.1rem;
border-radius: 4px;
border: 1px solid var(--fmq-rule-strong);
color: var(--fmq-ink);
text-decoration: none;
background: var(--fmq-paper);
}
.h-btn:hover {
border-color: var(--fmq-ink-3);
color: var(--fmq-ink);
}
.h-btn.pri {
background: var(--fmq-ink);
border-color: var(--fmq-ink);
color: var(--fmq-paper);
}
.h-btn.pri:hover {
background: var(--fmq-ink-2);
color: var(--fmq-paper);
}
.h-install {
display: flex;
align-items: center;
gap: 0.6rem;
margin-top: 1.25rem;
border: 1px solid var(--fmq-rule);
background: var(--fmq-paper-2);
border-radius: 4px;
padding: 0.4rem 0.45rem 0.4rem 0.75rem;
max-width: 22rem;
font-size: 0.875rem;
}
.h-install span {
color: var(--fmq-ink-3);
font-family: var(--fmq-font-mono);
}
.h-install code {
font-family: var(--fmq-font-mono);
color: var(--fmq-ink);
flex: 1;
background: none;
border: 0;
padding: 0;
}
</style>

View File

@@ -0,0 +1,44 @@
---
// Footer of the phone menu: the main sections, then GitHub and the theme.
import Default from '@astrojs/starlight/components/MobileMenuFooter.astro';
import { sections } from '../../lib/nav';
const base = import.meta.env.BASE_URL.replace(/\/$/, '');
const path = Astro.url.pathname;
---
<nav class="fmq-mnav" aria-label="Sections">
{
sections.map((s) => (
<a href={`${base}${s.href}`} aria-current={s.match(path, base) ? 'page' : undefined}>
{s.label}
</a>
))
}
</nav>
<Default />
<style>
.fmq-mnav {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 0.5rem;
border-top: 1px solid var(--fmq-rule);
padding-top: 0.75rem;
}
.fmq-mnav a {
text-align: center;
padding: 0.5rem 0.25rem;
border: 1px solid var(--fmq-rule);
border-radius: 4px;
color: var(--fmq-ink-2);
text-decoration: none;
font-size: 0.875rem;
font-weight: 500;
}
.fmq-mnav a[aria-current='page'] {
border-color: var(--fmq-bar);
background: var(--fmq-saffron-tint);
color: var(--fmq-ink);
}
</style>

View File

@@ -0,0 +1,87 @@
---
// Right column: the page contents, then the source files and guides of the page.
import Default from '@astrojs/starlight/components/PageSidebar.astro';
const { entry, toc } = Astro.locals.starlightRoute;
const data = entry.data as typeof entry.data & {
code?: string[];
guides?: { label: string; link: string }[];
};
const base = import.meta.env.BASE_URL.replace(/\/$/, '');
const code = data.code ?? [];
const guides = data.guides ?? [];
const withBase = (link: string) => (link.startsWith('/') && !link.startsWith(base + '/') ? base + link : link);
---
<Default />
{
toc && (code.length > 0 || guides.length > 0) && (
<div class="right-sidebar-panel fmq-extra sl-hidden lg:sl-block">
<div class="sl-container">
{guides.length > 0 && (
<nav aria-labelledby="fmq-guides">
<h2 id="fmq-guides">Guides</h2>
<ul>
{guides.map((g) => (
<li>
<a href={withBase(g.link)}>{g.label}</a>
</li>
))}
</ul>
</nav>
)}
{code.length > 0 && (
<nav aria-labelledby="fmq-code">
<h2 id="fmq-code">Code</h2>
<ul>
{code.map((file) => (
<li>
<a class="file" href={`${base}/source/${file}/`}>
{file}
</a>
</li>
))}
</ul>
</nav>
)}
</div>
</div>
)
}
<style>
.fmq-extra {
padding: 0 var(--sl-sidebar-pad-x) 1rem;
}
.fmq-extra nav {
border-top: 1px solid var(--fmq-rule);
padding-top: 0.9rem;
margin-bottom: 1rem;
}
.fmq-extra h2 {
margin-bottom: 0.5rem;
}
.fmq-extra ul {
list-style: none;
padding: 0;
margin: 0;
}
.fmq-extra li + li {
margin-top: 0.3rem;
}
.fmq-extra a {
display: block;
font-size: var(--sl-text-xs);
text-decoration: none;
color: var(--fmq-ink-2);
overflow-wrap: anywhere;
}
.fmq-extra a:hover {
color: var(--fmq-ink);
}
.fmq-extra a.file {
font-family: var(--fmq-font-mono);
font-size: 0.75rem;
color: var(--fmq-link);
}
</style>

View File

@@ -0,0 +1,54 @@
---
// Page title with the section label above it and an optional "since" badge.
import { sectionLabel } from '../../lib/nav';
const { entry, id } = Astro.locals.starlightRoute;
const data = entry.data as typeof entry.data & {
eyebrow?: string;
titleKind?: string;
since?: string;
searchTitle?: string;
};
const eyebrow = data.eyebrow ?? sectionLabel(id);
---
{eyebrow && <p class="fmq-eyebrow">{eyebrow}</p>}
<h1
id="_top"
class:list={{ code: !!data.titleKind }}
data-pagefind-meta={data.searchTitle ? `title:${data.searchTitle}` : undefined}
>
<span>{data.title}</span>
{data.titleKind && <span class="fmq-badge">{data.titleKind}</span>}
{data.since && <span class="fmq-badge since">since {data.since}</span>}
</h1>
<style>
h1 {
margin-top: 0.9rem;
font-size: var(--sl-text-h1);
line-height: 1.06;
font-weight: 800;
font-stretch: 112%;
letter-spacing: -0.02em;
color: var(--fmq-ink);
text-wrap: balance;
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.4rem 0.75rem;
}
h1.code {
font-family: var(--fmq-font-mono);
font-stretch: 100%;
font-weight: 700;
letter-spacing: -0.01em;
font-size: calc(var(--sl-text-h1) * 0.8);
overflow-wrap: anywhere;
}
h1 .fmq-badge {
font-size: 0.75rem;
font-family: var(--fmq-font-body);
letter-spacing: 0.08em;
}
</style>