Skip to content

Commit

Permalink
Number of preset queens for GpuSolver can now be set
Browse files Browse the repository at this point in the history
  • Loading branch information
olepoeschl committed Apr 28, 2022
1 parent 74799b2 commit df790c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/de/nqueensfaf/compute/GpuConstellationsGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

class GpuConstellationsGenerator {

private int N, preQueens = 5, L, mask, LD, RD, counter;
private int N, preQueens, L, mask, LD, RD, counter;
private int kbit, lbit;
private HashSet<Integer> startConstellations;
private ArrayList<Integer> jklList, startList;
ArrayList<Integer> ldList, rdList, colList, startjklList, symList;
int startConstCount;

// generate starting constellations
void genConstellations(int N, int WORKGROUP_SIZE) {
void genConstellations(int N, int WORKGROUP_SIZE, int preQueens) {
// the name says it all
ldList = new ArrayList<Integer>();
rdList = new ArrayList<Integer>();
Expand All @@ -37,6 +37,9 @@ void genConstellations(int N, int WORKGROUP_SIZE) {
this.N = N;
final int halfN = (N + 1) / 2;
startConstellations = new HashSet<Integer>();

// set number of preset queens
this.preQueens = preQueens;

// calculating start constellations with the first Queen on square (0,0) (corner)
for(int j = 1; j < N-2; j++) { // j is idx of Queen in last row
Expand Down
13 changes: 11 additions & 2 deletions src/de/nqueensfaf/compute/GpuSolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class GpuSolver extends Solver {
private long kernel;
private Long ldMem, rdMem, colMem, startjklMem, resMem, progressMem;
private int WORKGROUP_SIZE = 64;
private int PRE_QUEENS = 5;
private int globalWorkSize;

// calculation related stuff
Expand Down Expand Up @@ -351,7 +352,7 @@ private void init(MemoryStack stack) {
private void transferDataToDevice(MemoryStack stack) {
if(savedDuration == 0) { // if duration is 0, then restore() was not called
generator = new GpuConstellationsGenerator();
generator.genConstellations(N, WORKGROUP_SIZE);
generator.genConstellations(N, WORKGROUP_SIZE, PRE_QUEENS);

ldList = generator.ldList;
rdList = generator.rdList;
Expand Down Expand Up @@ -733,7 +734,7 @@ public int getGlobalWorkSize() {
public int getWorkgroupSize() {
return WORKGROUP_SIZE;
}

// sets WORKGROUP_SIZE
public void setWorkgroupSize(int s) {
if(device == 0) {
Expand All @@ -745,6 +746,14 @@ public void setWorkgroupSize(int s) {
}
WORKGROUP_SIZE = s;
}

// sets PRE_QUEENS
public void setNumberOfPresetQueens(int pq) {
if(pq < 4 || pq > 10) {
throw new IllegalArgumentException("Number of preset queens must be between 4 and 10");
}
PRE_QUEENS = pq;
}

// record class for saving and restoring
private record RestorationInformation(int N, long duration, long solutions, int startConstCount,
Expand Down

0 comments on commit df790c4

Please sign in to comment.