Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

When i run this code i keep getting errows like the picture below? im a trying to get help on fixing the code o where

When i run this code i keep getting errows like the picture below? im a trying to get help on fixing the code o where it runs?

#include

#include

#include

#include

#define num_threads 27

int valid[num_threads] = {0};

// Struct that stores the data to be passed to threads

typedef struct {

int row;

int column;

} parameters;

int sudoku[9][9] = {

{6, 2, 4, 5, 3, 9, 1, 8, 7},

{5, 1, 9, 7, 2, 8, 6, 3, 4},

{8, 3, 7, 6, 1, 4, 2, 9, 5},

{1, 4, 3, 8, 6, 5, 7, 2, 9},

{9, 5, 8, 2, 4, 7, 3, 6, 1},

{7, 6, 2, 3, 9, 1, 4, 5, 8},

{3, 7, 1, 9, 5, 6, 8, 4, 2},

{4, 9, 6, 1, 8, 2, 5, 7, 3},

{2, 8, 5, 4, 7, 3, 9, 1, 6}

};

// Method that determines if numbers 1-9 only appear once in a column

void *isColumnValid(void* param) {

// Confirm that parameters indicate a valid col subsection

parameters *params = (parameters*) param;

int row = params->row;

int col = params->column;

if (row != 0 || col > 8) {

fprintf(stderr, "Invalid row or column for col subsection! row=%d, col=%d ", row, col);

pthread_exit(NULL);

}

// Check if numbers 1-9 only appear once in the column

int validityArray[9] = {0};

int i;

for (i = 0; i

int num = sudoku[i][col];

if (num 9 || validityArray[num - 1] == 1) {

pthread_exit(NULL);

} else {

validityArray[num - 1] = 1;

}

}

// If reached this point, col subsection is valid.

valid[18 + col] = 1;

pthread_exit(NULL);

}

// Method that determines if numbers 1-9 only appear once in a row

void *isRowValid(void* param) {

// Confirm that parameters indicate a valid row subsection

parameters *params = (parameters*) param;

int row = params->row;

int col = params->column;

if (col != 0 || row > 8) {

fprintf(stderr, "Invalid row or column for row subsection! row=%d, col=%d ", row, col);

pthread_exit(NULL);

}

// Check if numbers 1-9 only appear once in the row

int validityArray[9] = {0};

int i;

for (i = 0; i

// If the corresponding index for the number is set to 1, and the number is encountered again,

// the valid array will not be updated and the thread will exit.

int num = sudoku[row][i];

if (num 9 || validityArray[num - 1] == 1) {

pthread_exit(NULL);

} else {

validityArray[num - 1] = 1;

}

}

// If reached this point, row subsection is valid.

valid[9 + row] = 1;

pthread_exit(NULL);

}

// Method that determines if numbers 1-9 only appear once in a 3x3 subsection

void *is3x3Valid(void* param) {

// Confirm that parameters indicate a valid 3x3 subsection

parameters *params = (parameters*) param;

int row = params->row;

int col = params->column;

if (row > 6 || row % 3 != 0 || col > 6 || col % 3 != 0) {

fprintf(stderr, "Invalid row or column for subsection! row=%d, col=%d ", row, col);

pthread_exit(NULL);

}

int validityArray[9] = {0};

int i, j;

for (i = row; i

for (j = col; j

int num = sudoku[i][j];

if (num 9 || validityArray[num - 1] == 1) {

pthread_exit(NULL);

} else {

validityArray[num - 1] = 1;

}

}

}

// If reached this point, 3x3 subsection is valid.

valid[row + col/3] = 1; // Maps the subsection to an index in the first 8 indices of the valid array

pthread_exit(NULL);

}

int main() {

pthread_t threads[num_threads];

int threadIndex = 0;

int i,j;

// Create 9 threads for 9 3x3 subsections, 9 threads for 9 columns and 9 threads for 9 rows.

// This will end up with a total of 27 threads.

for (i = 0; i

for (j = 0; j

if (i%3 == 0 && j%3 == 0) {

parameters *data = (parameters *) malloc(sizeof(parameters));

data->row = i;

data->column = j;

pthread_create(&threads[threadIndex++], NULL, is3x3Valid, data); // 3x3 subsection threads

}

if (i == 0) {

parameters *columnData = (parameters *) malloc(sizeof(parameters));

columnData->row = i;

columnData->column = j;

pthread_create(&threads[threadIndex++], NULL, isColumnValid, columnData); // column threads

}

if (j == 0) {

parameters *rowData = (parameters *) malloc(sizeof(parameters));

rowData->row = i;

rowData->column = j;

pthread_create(&threads[threadIndex++], NULL, isRowValid, rowData); // row threads

}

}

}

for (i = 0; i

pthread_join(threads[i], NULL); // Wait for all threads to finish

}

// If any of the entries in the valid array are 0, then the sudoku solution is invalid

for (i = 0; i

if (valid[i] == 0) {

printf("Sudoku solution is invalid! ");

return EXIT_SUCCESS;

}

}

printf("Sudoku solution is valid! ");

return EXIT_SUCCESS;

}

image text in transcribed

ameron@caneron-VirtualBox:~/hw2s gcc w2.c:17:1: -o hw2 hw2.c program error: stray \302, int row; in w2.c:17 : 1: w2.c:17:1: w2.c:17:1: w2.c:17:1: w2.c:17 : 1: w2.c:17:1: w2.c:17:1: w2.c:17:1: w2.c:17 : 1: w2.c:17:1: w2.c:17:1: w2.c:17:1: w2.c:17 : 1: w2.c:17:1: w2.c:17:1: w2.c:17:1: W2.c:17:1: error: error: error: error: error: error: error: error: error: error: error: error: error: error: error: error: error: stray stray stray stray stray stray stray stray stray stray stray stray stray stray stray stray stray \240' \302, \240' \302, \240' \302, \240' \302, \240' \302, \240' \302, \240' \302, \240' \302, \240 , in in in in in in in in in in in in in in in in 1n program program program program program program program program program program program program program program program program program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions