Skip to content

Commit d343c0e

Browse files
committed
Skeletons for QPEMPI, QPEOMP
1 parent 8712c5e commit d343c0e

File tree

2 files changed

+190
-2
lines changed

2 files changed

+190
-2
lines changed

QPEMPI.c

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,95 @@
1-
/* Skeleton for the Distributed-Memory OpenMPI Parallel Implementation */
1+
/* Distributed-Memory MPI Parallel Implementation - Runs commands from the query text file using connectEngine */
2+
3+
#define _POSIX_C_SOURCE 200809L // For strdup
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
#include <string.h>
7+
#include <time.h>
8+
#include <mpi.h>
9+
#include "../include/executeEngine-serial.h"
10+
#include "../include/connectEngine.h"
11+
// ANSI color codes for pretty printing
12+
#define CYAN "\x1b[36m"
13+
#define YELLOW "\x1b[33m"
14+
#define BOLD "\x1b[1m"
15+
#define RESET "\x1b[0m"
16+
17+
int main(int argc, char *argv[]) {
18+
19+
// NOTE: defaulting to sample queries file for ease of testing. Can implement CLI arg later.
20+
(void)argc; (void)argv; // Unused for now. Prevent warnings.
21+
22+
// Start a timer for total runtime statistics
23+
clock_t totalStart = clock();
24+
25+
// Instantiate an engine object to handle the execution of the query
26+
struct engineS *engine = initializeEngineSerial(
27+
numOptimalIndexes, // Number of indexes
28+
optimalIndexes, // Indexes to build B+ trees for
29+
(const int *)optimalIndexTypes, // Index types
30+
DATA_FILE,
31+
TABLE_NAME
32+
);
33+
34+
// End timer for engine initialization
35+
double initTimeTaken = ((double)clock() - totalStart) / CLOCKS_PER_SEC;
36+
37+
// Load the COMMANDS into memory (from COMMAND text file)
38+
const char *query_file = "sample-queries.txt";
39+
FILE *fp = fopen(query_file, "r");
40+
if (!fp) {
41+
perror("Failed to open query file");
42+
destroyEngineSerial(engine);
43+
return EXIT_FAILURE;
44+
}
45+
46+
fseek(fp, 0, SEEK_END);
47+
long fsize = ftell(fp);
48+
fseek(fp, 0, SEEK_SET);
49+
50+
char *buffer = malloc(fsize + 1);
51+
if (!buffer) {
52+
perror("Failed to allocate memory for query file");
53+
fclose(fp);
54+
destroyEngineSerial(engine);
55+
return EXIT_FAILURE;
56+
}
57+
size_t read_size = fread(buffer, 1, fsize, fp);
58+
if (read_size != (size_t)fsize) {
59+
perror("Failed to read query file");
60+
free(buffer);
61+
fclose(fp);
62+
destroyEngineSerial(engine);
63+
return EXIT_FAILURE;
64+
}
65+
buffer[fsize] = 0;
66+
fclose(fp);
67+
68+
// End timer for loading queries
69+
double loadTimeTaken = ((double)clock() - totalStart) / CLOCKS_PER_SEC;
70+
71+
// Run each command from the command input file
72+
char *query = strtok(buffer, ";");
73+
while (query) {
74+
// Trim whitespace
75+
query = trim(query);
76+
if (*query) {
77+
run_test_query(engine, query, ROW_LIMIT); // Limit output to 10 rows for testing
78+
}
79+
query = strtok(NULL, ";");
80+
}
81+
82+
free(buffer);
83+
destroyEngineSerial(engine);
84+
85+
// Print total runtime statistics in pretty colors
86+
double totalTimeTaken = ((double)clock() - totalStart) / CLOCKS_PER_SEC;
87+
printf(CYAN "======= Execution Summary =======" RESET "\n");
88+
printf(CYAN "Engine Initialization Time: " RESET YELLOW "%.4f seconds\n" RESET, initTimeTaken);
89+
printf(CYAN "Query Loading Time: " RESET YELLOW "%.4f seconds\n" RESET, loadTimeTaken - initTimeTaken);
90+
printf(CYAN "Query Execution Time: " RESET YELLOW "%.4f seconds\n" RESET, totalTimeTaken - loadTimeTaken);
91+
printf(BOLD CYAN "Total Execution Time: " RESET BOLD YELLOW "%.4f seconds" RESET "\n", totalTimeTaken);
92+
printf(CYAN "=================================" RESET "\n");
93+
94+
return EXIT_SUCCESS;
95+
}

QPEOMP.c

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,95 @@
1-
/* Skeleton for the Shared-Memory OpenMP Parallel Implementation */
1+
/* Shared-Memory OpenMP Parallel Implementation - Runs commands from the query text file using connectEngine */
2+
3+
#define _POSIX_C_SOURCE 200809L // For strdup
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
#include <string.h>
7+
#include <time.h>
8+
#include <omp.h>
9+
#include "../include/executeEngine-serial.h"
10+
#include "../include/connectEngine.h"
11+
// ANSI color codes for pretty printing
12+
#define CYAN "\x1b[36m"
13+
#define YELLOW "\x1b[33m"
14+
#define BOLD "\x1b[1m"
15+
#define RESET "\x1b[0m"
16+
17+
int main(int argc, char *argv[]) {
18+
19+
// NOTE: defaulting to sample queries file for ease of testing. Can implement CLI arg later.
20+
(void)argc; (void)argv; // Unused for now. Prevent warnings.
21+
22+
// Start a timer for total runtime statistics
23+
clock_t totalStart = clock();
24+
25+
// Instantiate an engine object to handle the execution of the query
26+
struct engineS *engine = initializeEngineSerial(
27+
numOptimalIndexes, // Number of indexes
28+
optimalIndexes, // Indexes to build B+ trees for
29+
(const int *)optimalIndexTypes, // Index types
30+
DATA_FILE,
31+
TABLE_NAME
32+
);
33+
34+
// End timer for engine initialization
35+
double initTimeTaken = ((double)clock() - totalStart) / CLOCKS_PER_SEC;
36+
37+
// Load the COMMANDS into memory (from COMMAND text file)
38+
const char *query_file = "sample-queries.txt";
39+
FILE *fp = fopen(query_file, "r");
40+
if (!fp) {
41+
perror("Failed to open query file");
42+
destroyEngineSerial(engine);
43+
return EXIT_FAILURE;
44+
}
45+
46+
fseek(fp, 0, SEEK_END);
47+
long fsize = ftell(fp);
48+
fseek(fp, 0, SEEK_SET);
49+
50+
char *buffer = malloc(fsize + 1);
51+
if (!buffer) {
52+
perror("Failed to allocate memory for query file");
53+
fclose(fp);
54+
destroyEngineSerial(engine);
55+
return EXIT_FAILURE;
56+
}
57+
size_t read_size = fread(buffer, 1, fsize, fp);
58+
if (read_size != (size_t)fsize) {
59+
perror("Failed to read query file");
60+
free(buffer);
61+
fclose(fp);
62+
destroyEngineSerial(engine);
63+
return EXIT_FAILURE;
64+
}
65+
buffer[fsize] = 0;
66+
fclose(fp);
67+
68+
// End timer for loading queries
69+
double loadTimeTaken = ((double)clock() - totalStart) / CLOCKS_PER_SEC;
70+
71+
// Run each command from the command input file
72+
char *query = strtok(buffer, ";");
73+
while (query) {
74+
// Trim whitespace
75+
query = trim(query);
76+
if (*query) {
77+
run_test_query(engine, query, ROW_LIMIT); // Limit output to 10 rows for testing
78+
}
79+
query = strtok(NULL, ";");
80+
}
81+
82+
free(buffer);
83+
destroyEngineSerial(engine);
84+
85+
// Print total runtime statistics in pretty colors
86+
double totalTimeTaken = ((double)clock() - totalStart) / CLOCKS_PER_SEC;
87+
printf(CYAN "======= Execution Summary =======" RESET "\n");
88+
printf(CYAN "Engine Initialization Time: " RESET YELLOW "%.4f seconds\n" RESET, initTimeTaken);
89+
printf(CYAN "Query Loading Time: " RESET YELLOW "%.4f seconds\n" RESET, loadTimeTaken - initTimeTaken);
90+
printf(CYAN "Query Execution Time: " RESET YELLOW "%.4f seconds\n" RESET, totalTimeTaken - loadTimeTaken);
91+
printf(BOLD CYAN "Total Execution Time: " RESET BOLD YELLOW "%.4f seconds" RESET "\n", totalTimeTaken);
92+
printf(CYAN "=================================" RESET "\n");
93+
94+
return EXIT_SUCCESS;
95+
}

0 commit comments

Comments
 (0)