Skip to content

Commit 2c8e38f

Browse files
committed
Fixing MPI segfaults
Now everything can run smoothly with the proper run commands.
1 parent 32fca4a commit 2c8e38f

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

QPEMPI

-182 KB
Binary file not shown.

QPEMPI.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,6 @@ int main(int argc, char *argv[]) {
215215

216216
// Execute Queries - Distribute across MPI ranks
217217
for (int i = 0; i < query_count; i++) {
218-
// Round-robin distribution: each rank processes queries where i % size == rank
219-
if (i % size != rank) continue;
220-
221218
char *query = trim(queries[i]);
222219
if (!*query) continue;
223220

@@ -234,6 +231,15 @@ int main(int argc, char *argv[]) {
234231

235232
if (num_tokens > 0) {
236233
parsed = parse_tokens(tokens);
234+
} else {
235+
parseFailed = true;
236+
}
237+
238+
bool is_owner = (i % size == rank);
239+
bool is_collective = (parsed.command == CMD_INSERT || parsed.command == CMD_DELETE);
240+
bool should_execute = is_owner || is_collective;
241+
242+
if (should_execute && num_tokens > 0) {
237243

238244
// Prepare Select Items
239245
const char *selectItems[parsed.num_columns > 0 ? parsed.num_columns : 1];
@@ -278,16 +284,14 @@ int main(int argc, char *argv[]) {
278284
}
279285

280286
execTime = MPI_Wtime() - start;
281-
} else {
282-
parseFailed = true;
283287
}
284288

285289
// Synchronize all ranks before printing to ensure ordered output
286290
MPI_Barrier(MPI_COMM_WORLD);
287291

288292
// Print results in rank order
289293
for (int print_rank = 0; print_rank < size; print_rank++) {
290-
if (rank == print_rank) {
294+
if (rank == print_rank && is_owner) {
291295
printf("Executing Query: %s\n", query);
292296

293297
if (parseFailed) {
@@ -335,11 +339,11 @@ int main(int argc, char *argv[]) {
335339
printf(CYAN "=================================" RESET "\n");
336340
}
337341

338-
printf("Rank %d: Freeing buffer...\n", rank);
342+
// printf("Rank %d: Freeing buffer...\n", rank);
339343
free(buffer);
340-
printf("Rank %d: Destroying engine...\n", rank);
344+
// printf("Rank %d: Destroying engine...\n", rank);
341345
destroyEngineMPI(engine);
342-
printf("Rank %d: Finalizing MPI...\n", rank);
346+
// printf("Rank %d: Finalizing MPI...\n", rank);
343347

344348
MPI_Finalize();
345349
return EXIT_SUCCESS;

QPEOMP

-195 KB
Binary file not shown.

engine/mpi/executeEngine-mpi.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,12 @@ struct resultSetS *executeQuerySelectMPI(
361361
// Get all indexed attributes in the WHERE clause, using the B+ tree indexes where possible
362362
struct whereClauseS *wc = whereClause;
363363
while (wc != NULL) {
364+
// Skip nested conditions for index optimization (attribute is NULL)
365+
if (wc->attribute == NULL) {
366+
wc = wc->next;
367+
continue;
368+
}
369+
364370
for (int i = 0; i < engine->num_indexes; i++) {
365371
if (strcmp(wc->attribute, engine->indexed_attributes[i]) == 0) {
366372
// Use B+ tree index for this attribute

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
CC := gcc
1111
CSTD := -std=c11
12-
CFLAGS := $(CSTD) -Wall -Wextra -O2 -g -Iinclude
12+
CFLAGS := $(CSTD) -Wall -Wextra -O2 -g -Iinclude -Wno-unused-variable # Supress unused variable warnings
1313
LDFLAGS :=
1414
LDLIBS :=
1515

0 commit comments

Comments
 (0)