Multiprocessor
Multiprocessing Manager
Last updated
Multiprocessing Manager
Last updated
Multiprocessor is a powerful package enabling developers to manually spawn EVM instances for parallel processing, allows the programmer to fully leverage the computation power of modern multiple processor design. These jobs run in isolated EU instances and are subject to the same commutativity checks as EOA-submitted transactions. The system automatically detects conflicts and merges safe updates deterministically.
The parent execution unit (EU) spawns multiple child EUs to execute transactions in parallel. Each child runs in isolation, and its state changes are passed to the Conflict Detector. Only clean, non-conflicting changes are merged back into the parent EU, ensuring deterministic and safe parallelism.
Storage: Child EUs receive a snapshot copy of the parent’s storage state at the moment of forking. They do not write directly to global storage during execution. They accumulate tentative state changes in a local cache. After execution, these changes are passed to the Conflict Detector, only clean, non-conflicting storage changes are committed back to the parent EU.
Memory: Each spawned EU gets its own memory space. Memory is not shared, not snapshotted, and has no impact on conflict detection. You can use memory freely within each parallel job without restriction. Since they have no impact on the global state.
The conflict rules applied to EOA transitions are also applicable to these multiprocessor-spawned tasks.
Multiprocess
Manages job queue and controls execution across isolated EUs.
push(...)
Adds a job to the queue — each job includes a gas limit, value to transfer (optional, 0 by default), target contract, and calldata.
run()
Executes all jobs in parallel.
Conflict Detection
After run()
is called, Arcology automatically performs conflict detection to ensure state consistency. Any jobs that violate commutativity (e.g., write to the same storage key) are reverted and excluded from the final state merge.
The examples highlight the main features and applications of Arcology's multiprocessing capability. They demonstrate how Arcology's technology can enhance the execution of smart contracts and provide significant benefits in terms of scalability and efficiency.
This contract illustrates how two independent value assignments can be executed in parallel, safely merged back into the global state, and verified for correctness — all within a single transaction.
The contract declares two state variables, _1
and _2
, and sets up two parallel jobs using the Multiprocess
API with two execution units. Job 0 runs assigner(0)
, setting _1 = 10
, while Job 1 runs assigner(1)
, setting _2 = 11
.
These jobs are executed in parallel inside isolated EU instances using mp.run()
. After execution, Arcology’s conflict detector verifies that the two jobs modify separate, non-overlapping state, confirming no conflicts.
Since the updates are commutative and independent, their changes are safely merged back into the parent context. The final assertions verify that _1
is 10 and _2
is 11, confirming the success of deterministic parallel execution.
The contract ParaAssignmentWithConflict
contains a function call()
that utilizes the Multiprocess
contract to execute the function assigner()
in parallel. The assigner()
function takes an input v
and assigns the value v + 10
to the element at index v
in the results
array.
This example shows how Arcology detects and resolves write-write conflicts at runtime. Two jobs write to the same storage slot (results[0]
). The system reverts one of them while preserving deterministic execution for the others. Only non-conflicting results are merged into the final state.
Here's a step-by-step explanation of what happens:
The call()
function is called, and it creates a new instance of the Multiprocess
contract with 2 threads (processes).
Two messages are pushed into the Multiprocess
container with the function signature "assigner(uint256)" and respective values 0
and 1
.
The mp.run()
function is called, which executes the two messages in parallel using the specified number of threads (2).
Arcology detects the overlapping write to the same storage key. One of the conflicting jobs is reverted. The third job (assigner(1)
) writes to results[1]
and is conflict-free, so it’s committed.
Only one write to results[0]
is retained.results[0] == 10
, results[1] == 11
so the assertions pass.
Parallel Minting Transactions: In the call
function of the SubcurrencyCaller
contract, four minting transactions are added to the Multiprocess
queue. These transactions are designed to mint tokens for four different addresses: Alice, Bob, Carol, and Dave.
Execution and Verification: After adding the minting transactions to the Multiprocess
queue using mp.push()
, the contract checks if the number of transactions in the queue is equal to 4 by using mp.length()
. This ensures that all four minting transactions have been successfully added to the queue.
Parallel Execution: The mp.run()
function is then called, which executes all the minting transactions in parallel. Arcology's parallel processing capability allows these transactions to be processed simultaneously, reducing the overall execution time and gas cost.
Verification of Minted Balances: After the parallel execution, the contract verifies the balances of the four addresses by calling the getter
function of the Subcurrency
contract. This demonstrates that the transactions were executed correctly, and the minted amounts were applied to the corresponding addresses.
Arcology ensures data consistency and integrity when concurrent operations are performed on shared state variables, allowing developers to harness the power of parallel execution without worrying about data corruption or conflicts.
The offers a queue, which temporarily holds a list of tasks before execution begins. State consistency is rigorously guaranteed all the time. The actual parallel execution of the task in the queue won't start until the function run()
is called. After execution, it checks for conflicts (e.g., write to same storage) and only merges non-conflicting (commutative) state changes back into the main state.
The example comes from the official Ethereum documentation and implements the simplest form of a cryptocurrency. It isn't a standard ERC-20 contract, but it’s complex enough to cover many of the issues developers may encounter when using a multiprocessor execution in contrasts.
The SubcurrencyCaller
contract utilizes Arcology's library to perform parallel processing of multiple minting transactions on the contract, greatly improving the overall efficiency.