cortex_run_attached_mod Module

Spec §11.1, §11.2, §11.3. Identical dispatch on every rank so collective MPI ops in solver_session_* line up. Only rank 0 owns the socket and writes replies.



Variables

Type Visibility Attributes Name Initial
integer, private, save :: g_fd = -1

Functions

private pure function opcode_kind_matches(opcode_kind, expected_kind) result(matches)

True when a SET_/GET_ opcode's own wire kind is compatible with the schema's expected_kind for the target key. Choice-typed keys (e.g. flux_scheme) travel as JSON strings on the wire and are accepted by SET_STRING/GET_STRING, mirroring decode_set_value's existing wire-compatible grouping of cfg_kind_string with cfg_kind_choice.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: opcode_kind
integer, intent(in) :: expected_kind

Return Value logical

private pure function kind_label(kind) result(label)

Human-readable label for a cfg_kind_* tag, used only in type_mismatch messages (never as a wire code).

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: kind

Return Value character(len=16)

private function reject_kind_mismatch(op, id, key, opcode_kind, expected_kind, reply_header) result(mismatch)

Rank-0-only ok=false type_mismatch reply for a SET_/GET_ opcode whose own kind does not match the schema's expected_kind for key. Callers must check session_schema_lookup's ok first and keep reporting unknown_key when the key itself is not found; this only covers a key that does exist but was addressed by the wrong-kind opcode (e.g. SET_INTEGER on the real-valued key cfl), aligning the real worker with the cortex stub's stricter behaviour.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: op
character(len=*), intent(in) :: id
character(len=*), intent(in) :: key
integer, intent(in) :: opcode_kind
integer, intent(in) :: expected_kind
integer(kind=int8), intent(out), allocatable :: reply_header(:)

Return Value logical

private function op_failed(id, opcode, status, message, reply_header) result(failed)

Turn a failed session operation into a proper reply-level error and tell the caller to stop handling the current opcode. Returns .true. on failure.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: id
character(len=*), intent(in) :: opcode
integer, intent(in) :: status
character(len=*), intent(in) :: message
integer(kind=int8), intent(inout), allocatable :: reply_header(:)

Return Value logical


Subroutines

public subroutine cortex_run_attached(uri, worker_name)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: uri
character(len=*), intent(in), optional :: worker_name

private subroutine dispatch_opcode(session, op, id, header, reply_header, reply_payload, done)

Arguments

Type IntentOptional Attributes Name
type(solver_session_t), intent(inout) :: session
character(len=*), intent(in) :: op
character(len=*), intent(in) :: id
integer(kind=int8), intent(in) :: header(:)
integer(kind=int8), intent(out), allocatable :: reply_header(:)
integer(kind=int8), intent(out), allocatable :: reply_payload(:)
logical, intent(inout) :: done

private subroutine handle_copy_solution(session, id, op, header, reply_header, reply_payload, status, message)

Service a COPY_SOLUTION request.

Read more…

Arguments

Type IntentOptional Attributes Name
type(solver_session_t), intent(inout) :: session
character(len=*), intent(in) :: id
character(len=*), intent(in) :: op
integer(kind=int8), intent(in) :: header(:)
integer(kind=int8), intent(out), allocatable :: reply_header(:)
integer(kind=int8), intent(out), allocatable :: reply_payload(:)
integer, intent(out) :: status
character(len=*), intent(out) :: message

private subroutine handle_copy_solution_2d(session, id, op, n_prims, prim_names, reply_header, reply_payload, status, message)

2D COPY_SOLUTION: session packs one i-fastest float64 block per requested primitive (x,y,rho,u,v,p) into a flat buffer; rank 0 transfers it to the binary payload and emits the nx/ny-bearing reply header. Collective.

Arguments

Type IntentOptional Attributes Name
type(solver_session_t), intent(inout) :: session
character(len=*), intent(in) :: id
character(len=*), intent(in) :: op
integer, intent(in) :: n_prims
character(len=16), intent(in) :: prim_names(:)
integer(kind=int8), intent(out), allocatable :: reply_header(:)
integer(kind=int8), intent(out), allocatable :: reply_payload(:)
integer, intent(out) :: status
character(len=*), intent(out) :: message

private subroutine send_hello(fd, worker_name)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: fd
character(len=*), intent(in) :: worker_name

private subroutine bcast_bytes(buf)

Arguments

Type IntentOptional Attributes Name
integer(kind=int8), intent(inout), allocatable :: buf(:)

private subroutine encode_keyed_failure(op, id, code, message, reply_header)

Encode a rank-0-only ok=false reply for a config-key read/write. Centralised so the same code shape is used by every SET/GET arm.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: op
character(len=*), intent(in) :: id
character(len=*), intent(in) :: code
character(len=*), intent(in) :: message
integer(kind=int8), intent(out), allocatable :: reply_header(:)

private subroutine session_schema_lookup(session, key, idx, expected_kind, ok, message)

Resolve a config key against the schema matching the session's dim. dim=1 behaviour is byte-identical to the old direct schema_lookup call.

Arguments

Type IntentOptional Attributes Name
type(solver_session_t), intent(in) :: session
character(len=*), intent(in) :: key
integer, intent(out) :: idx
integer, intent(out) :: expected_kind
logical, intent(out) :: ok
character(len=*), intent(out) :: message

private subroutine emit_progress_tick(iter, sim_time, dt, residual, wallclock_s)

Tick handler bound on rank 0 only. Encodes a PROGRESS_TICK and writes it to the existing attached-mode socket fd.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: iter
real(kind=wp), intent(in) :: sim_time
real(kind=wp), intent(in) :: dt
real(kind=wp), intent(in) :: residual
real(kind=wp), intent(in) :: wallclock_s