A C++ concurrency assignment that generates valid NS1D(n) sequences using parallel depth-first search, worker threads, a channel abstraction, and producer-consumer output.
Given an odd integer n > 1, the program searches for integer sequences of length (n - 1) / 2 + 1 that satisfy the assignment's NS1D rules. The search space grows quickly, so the implementation parallelizes the work across multiple threads and writes valid sequences to an output file.
The program is structured around a map/reduce-style workflow:
- Worker threads split the search space by assigning different starting branches.
- Each worker performs DFS over its subset of the search tree.
- Valid sequences are sent through a thread-safe channel.
- A dedicated output thread consumes completed sequences and writes them to disk.
- Atomic counters track global progress without unnecessary locking.
Key concurrency concepts demonstrated:
- Worker thread pool
- Producer-consumer communication
- Channel abstraction using
std::mutex,std::condition_variable, andstd::queue - Atomic counters for shared progress tracking
- Reduced file I/O contention through a single writer thread
.
|-- Makefile
|-- include/
| |-- channel.h
| `-- ns1d0.h
|-- src/
| |-- main.cpp
| `-- ns1d0.cpp
`-- sequence.pdf
makeThis compiles the program to:
bin/sequence
./bin/sequence n output_fileExample:
./bin/sequence 7 seq7.txtMakefile shortcuts:
make test7
make test9
make test11
make test13The largest value that ran in a reasonable time on the original test machine was n = 11. The search space grows combinatorially, so parallelism helps but does not eliminate the underlying exponential growth.
This project is useful portfolio evidence for systems and quant-oriented engineering because it demonstrates practical C++ concurrency: splitting CPU-heavy work, avoiding shared-state races, coordinating threads through channels, and isolating file output behind a single consumer.