{"id":22046613,"url":"https://github.com/vitorebatista/n-queens-mpi","last_synced_at":"2026-07-10T21:31:34.344Z","repository":{"id":73492723,"uuid":"220577680","full_name":"vitorebatista/n-queens-mpi","owner":"vitorebatista","description":null,"archived":false,"fork":false,"pushed_at":"2019-11-14T16:25:21.000Z","size":9,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-26T03:28:42.549Z","etag":null,"topics":["mpi","nqueens-problem","nqueens-solution"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vitorebatista.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-09T02:04:35.000Z","updated_at":"2019-11-15T19:35:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"b0010cc2-aeea-4a23-a6eb-f672555a75ba","html_url":"https://github.com/vitorebatista/n-queens-mpi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vitorebatista/n-queens-mpi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitorebatista%2Fn-queens-mpi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitorebatista%2Fn-queens-mpi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitorebatista%2Fn-queens-mpi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitorebatista%2Fn-queens-mpi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vitorebatista","download_url":"https://codeload.github.com/vitorebatista/n-queens-mpi/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitorebatista%2Fn-queens-mpi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35344523,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-10T02:00:06.465Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mpi","nqueens-problem","nqueens-solution"],"created_at":"2024-11-30T13:19:23.280Z","updated_at":"2026-07-10T21:31:34.339Z","avatar_url":"https://github.com/vitorebatista.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# N-Queens with MPI\n\nParallel and sequential solvers for the N-Queens problem, written in C. The parallel version distributes the search across processes with [MPI](https://www.open-mpi.org/) using a master/worker scheme: the master hands out starting columns for the first queen, and workers run a backtracking search over their sub-trees and report solution counts back.\n\n## The N-Queens problem\n\nThe N-Queens problem asks how to place *n* queens on an *n* × *n* chessboard so that no queen attacks another — no two queens may share a row, column, or diagonal. Solutions exist for *n* = 1 and every *n* ≥ 4.\n\n### Rejecting equivalent solutions\n\nMany solutions are equivalent to each other under symmetry operations. Some boards have *rotational symmetry*: rotating them by 180° (or even 90°) produces the exact same configuration. The numbering below marks queens that map to each other under rotation:\n\n```\n      .  1  .  .  .  .                .  1  .  .  .\n      .  .  .  2  .  .                .  .  .  .  1\n      .  .  .  .  .  3                .  .  2  .  .\n      3  .  .  .  .  .                1  .  .  .  .\n      .  .  2  .  .  .                .  .  .  1  .\n      .  .  .  .  1  .          Symmetric on 90° rotation\nSymmetric on 180° rotation\n```\n\nIf a solution has no rotational symmetry, successive 90° rotations generate other solutions that will also be discovered during the search. Besides rotations there is mirror reflection: by the nature of the problem a valid solution cannot be its own mirror image, so every solution also has mirror images that show up during processing. A solution without any symmetry therefore belongs to a family of eight equivalent boards — rotations and reflections of one base configuration:\n\n```\n       Original                       Vertical mirror\n         1  .  .  .  .                  .  .  .  .  1\n         .  .  2  .  .                  .  .  2  .  .\n         .  .  .  .  3                  3  .  .  .  .\n         .  4  .  .  .                  .  .  .  4  .\n         .  .  .  5  .                  .  5  .  .  .\n\n       90 degree rotation             Anti-diagonal mirror\n         .  .  .  .  1                  .  .  3  .  .\n         .  4  .  .  .                  5  .  .  .  .\n         .  .  .  2  .                  .  .  .  2  .\n         5  .  .  .  .                  .  4  .  .  .\n         .  .  3  .  .                  .  .  .  .  1\n\n       180 degree rotation            Horizontal mirror\n         .  5  .  .  .                  .  .  .  5  .\n         .  .  .  4  .                  .  4  .  .  .\n         3  .  .  .  .                  .  .  .  .  3\n         .  .  2  .  .                  .  .  2  .  .\n         .  .  .  .  1                  1  .  .  .  .\n\n       270 degree rotation            Diagonal mirror\n         .  .  3  .  .                  1  .  .  .  .\n         .  .  .  .  5                  .  .  .  4  .\n         .  2  .  .  .                  .  2  .  .  .\n         .  .  .  4  .                  .  .  .  .  5\n         1  .  .  .  .                  .  .  3  .  .\n```\n\nRejecting equivalents does not require storing previously accepted solutions. The board is represented as an array of column positions, which can be read as an N-digit number and compared lexicographically. Adopt the rule that only the *first* solution in that ordering is accepted among a family of equivalents: rotate each candidate through successive 90° increments, and if any rotation compares as \"smaller\", reject the candidate. For mirror images, generate the mirror and rotate it through the three 90° increments to check all four reflected variants.\n\n### Solution counts\n\nNumber of solutions for placing *n* queens on an *n* × *n* board — unique (fundamental) and total:\n\n| n  | Fundamental | All         |\n|----|-------------|-------------|\n| 1  | 1           | 1           |\n| 2  | 0           | 0           |\n| 3  | 0           | 0           |\n| 4  | 1           | 2           |\n| 5  | 2           | 10          |\n| 6  | 1           | 4           |\n| 7  | 6           | 40          |\n| 8  | 12          | 92          |\n| 9  | 46          | 352         |\n| 10 | 92          | 724         |\n| 11 | 341         | 2,680       |\n| 12 | 1,787       | 14,200      |\n| 13 | 9,233       | 73,712      |\n| 14 | 45,752      | 365,596     |\n| 15 | 285,053     | 2,279,184   |\n| 16 | 1,846,955   | 14,772,512  |\n| 17 | 11,977,939  | 95,815,104  |\n| 18 | 83,263,591  | 666,090,624 |\n\n## Repository layout\n\n| File | Description |\n|------|-------------|\n| `seq-nqueens.c` | Sequential backtracking solver |\n| `mpi-nqueens.c` | Parallel master/worker MPI solver |\n| `util.c` | Shared board, rotation, and timing helpers |\n| `mp` | Example MPI hostfile |\n| `time-seq-nqueens.csv`, `time-mpi-nqueens.csv` | Timing results |\n| `test/` | Small standalone test solver |\n\n## Requirements\n\n- A C compiler\n- An MPI implementation (e.g. [Open MPI](https://www.open-mpi.org/) or [MPICH](https://www.mpich.org/)) providing `mpicc` and `mpirun`\n- `make`\n\n## How to run\n\n1. **Build.** From the repository root:\n\n   ```sh\n   make\n   ```\n\n   This compiles both the sequential and the MPI executables.\n\n2. **Run the sequential version**, passing the number of queens as the first argument:\n\n   ```sh\n   ./seq-nqueens 12\n   ```\n\n3. **Run the MPI version.** Locally, just pick the number of processes:\n\n   ```sh\n   mpirun -np 8 ./mpi-nqueens 12\n   ```\n\n   To run across multiple machines, edit the hostfile `mp` (one `hostname slots=N` entry per machine) and pass it to `mpirun`:\n\n   ```sh\n   mpirun -np 8 --hostfile mp ./mpi-nqueens 12\n   ```\n\n4. **Clean up** build artifacts:\n\n   ```sh\n   make clean\n   ```\n\n## License\n\nMIT — see [LICENSE](LICENSE).\n\n## References\n\n- Timothy J. Rolfe, [*Optimal Queens*](http://penguin.ewu.edu/~trolfe/Queens/OptQueen.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitorebatista%2Fn-queens-mpi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvitorebatista%2Fn-queens-mpi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitorebatista%2Fn-queens-mpi/lists"}