Skip to content

Parallelism

Namespace Nfty.Core in assembly Nfty.Core.

public sealed record Parallelism

How wide independent per-item work may run. Output never depends on it: every parallel step writes to its own slot, so one thread and many give byte-identical results.

Remarks

Equality is by Parallelism.Requested alone. The degree actually used is Parallelism.Effective, which the library clamps to the machine's logical processor count.

Constructors

Parallelism(int)

public Parallelism(int Requested);

Parameters

  • Requested (int) - The degree asked for; 0 means every logical processor. Negative is refused.

Remarks

Equality is by Parallelism.Requested alone. The degree actually used is Parallelism.Effective, which the library clamps to the machine's logical processor count.

Fields

EnvironmentVariable

public const string EnvironmentVariable = "NFTY_THREADS";

The environment variable that overrides the saved or default count for one run.

Properties

All

public static Parallelism All { get; }

Every logical processor.

Default

public static Parallelism Default { get; }

The default degree.

DefaultDegree

public static int DefaultDegree { get; }

Two thirds of the logical processors, floored, and at least one.

Effective

public int Effective { get; }

The degree that actually runs: clamped to between 1 and the logical processor count.

IsSequential

public bool IsSequential { get; }

True when work runs on the calling thread.

LogicalProcessors

public static int LogicalProcessors { get; }

The machine's logical processor count (affinity- and container-aware).

Requested

public int Requested { get; }

The degree requested; 0 means all.

Sequential

public static Parallelism Sequential { get; }

One thread, on a plain loop with no scheduler involved.

Methods

TryParse(string?, Parallelism)

public static bool TryParse(string? text, out Parallelism parallelism);

Reads a thread count as people spell it: a whole number, or max; 0 and max both mean every logical processor. The one rule the CLI's --threads, the NFTY_THREADS variable and the app's Settings card all share. Nothing is clamped here: a count above the machine's is a valid request, and Parallelism.Effective brings it down.

Parameters

  • text (string?) - The text, with surrounding whitespace ignored.
  • parallelism (Parallelism) - The count when this returns true; Parallelism.Default otherwise.

Returns. False for empty text, a sign, a fraction or anything else that is not a whole number or max.