Skip to content
Snippets Groups Projects
Commit eee57acd authored by Brandon Rodriguez's avatar Brandon Rodriguez
Browse files

Create initial program setup logic

parent bc9d8098
Branches
No related merge requests found
# Load Balancing & Isoefficiency > Documents > References.md
## Description
All references to external logic. Includes anything from stack overflow links to notes about logic from previous works.
## References
### Parallelization
#### General Paralellization Logic
Most parallelization logic is from the book "Introduction to Parallel Programming, by Peter S Pancheco".
#### Getting Processor Count
<https://stackoverflow.com/a/47520857>
### Data Types
#### Various C Data Types
<https://en.wikipedia.org/wiki/C_data_types>
#### Data Type Limits
<https://www.tutorialspoint.com/c_standard_library/limits_h.htm>
### Other
#### strtol Function
<https://www.tutorialspoint.com/c_standard_library/c_function_strtol.htm>
/**
* An implementation of various Load Balancing schemes, to examine the concepts of Isoefficiency.
*/
// Import headers.
#include <ctype.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
// Method Declaration.
// Global Variables.
/**
* Program's main. Initialized and runs program.
*/
int main(int argc, char* argv[]) {
printf("Initializing program.\n");
printf("Terminating program.\n");
}
all: all:
gcc -Wall -Wpedantic -std=c99 main.c -g -o main.out -pthread gcc -Wall -Wpedantic -std=c99 src/main.c -g -o main.out -pthread
/**
* An implementation of various Load Balancing schemes, to examine the concepts of Isoefficiency.
*/
// Import headers.
#include <ctype.h>
#include <limits.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/sysinfo.h>
#include <unistd.h>
// Method Declaration.
void validate_args();
void display_max_types();
void simulate_load();
// Global Variables.
int thread_count;
int seconds_per_index;
int indexes_per_load;
int total_loads;
/**
* Program's main. Initialized and runs program.
*/
int main(int argc, char* argv[]) {
printf("Initializing program.\n");
printf("\n");
// Validate program args.
validate_args(argc, argv);
// If we got this far, then args are valid. Proceed with program.
int total_processors = get_nprocs();
// Display args.
printf("Provided values:");
printf(" %i Total Loads\n", total_loads);
printf(" %i Indexes Per Load\n", indexes_per_load);
printf(" %i Seconds Per Index\n", seconds_per_index);
printf("\n");
printf(" Total Expected work = TotalLoads * IndexesPerLoad * SecondsPerIndex\n");
printf(" = %i * %i * %i\n", total_loads, indexes_per_load, seconds_per_index);
int seconds_active_work = total_loads * indexes_per_load * seconds_per_index;
printf(" = %i Seconds Active Work\n", seconds_active_work);
printf(" = %i Minutes Active Work\n", (seconds_active_work / 60));
printf("\n");
printf(" %i Total System Processors\n", total_processors);
printf("\n");
printf(" Expected total execution time with ideal processor usage:\n");
printf(" (Work / Processor Count) = %i Minutes\n", (seconds_active_work / 60 / total_processors));
printf("\n");
// Run program.
display_max_types();
// simulate_load();
printf("\n");
printf("Terminating program.\n");
exit(0);
}
/**
* Validate program args.
*/
void validate_args(int argc, char* argv[]) {
if (argc == 4) {
// Expected number of params. Validate passed args.
// Validate "seconds_per_index" value. Should be between 1 and 10.
seconds_per_index = strtol(argv[1], NULL, 10);
if ((seconds_per_index < 1) || (seconds_per_index > 10)) {
printf("Arg1 (seconds_per_index) should be int between 1 and 10.\n");
printf("\n");
printf("Terminating program.\n");
exit(1);
}
// Validate "indexes_per_load" value. Should be between 100 and 10,000.
indexes_per_load = strtol(argv[2], NULL, 10);
if ((indexes_per_load < 100) || (indexes_per_load > 10000)) {
printf("Arg2 (indexes_per_load) should be int between 100 and 10,000.\n");
printf("\n");
printf("Terminating program.\n");
exit(1);
}
// Validate "total_loads" value. Should be between 100 and 10,000.
total_loads = strtol(argv[3], NULL, 10);
if ((total_loads < 100) || (total_loads > 10000)) {
printf("Arg3 (total_loads) should be int between 100 and 10,000.\n");
printf("\n");
printf("Terminating program.\n");
exit(1);
}
} else if (argc > 4) {
// Too many args. Error.
printf("Too many args passed. Got %i. Expected 3.\n", (argc - 1));
printf("\n");
printf("Terminating program.\n");
exit(1);
} else {
// Too few args. Error.
printf("Too few args passed. Got %i. Expected 3.\n", (argc - 1));
printf("\n");
printf("Terminating program.\n");
exit(1);
}
}
/**
* Helper function to display some max values for system.
*/
void display_max_types() {
printf("\n\n");
printf("Int max is %i.\n", INT_MAX);
printf("Unsigned Int max is %u.\n", UINT_MAX);
printf("Long Max is %ld.\n", LONG_MAX);
printf("Unsigned Long max is %lu.\n", ULONG_MAX);
printf("\n\n");
}
/**
* Function to simulate working on a load.
*/
void simulate_load() {
unsigned int load_counter = 0;
unsigned long index = 0;
// Iterate through loads. Each load has indexes to simulate "work".
while (load_counter < total_loads) {
// Increment load num.
load_counter += 1;
// Simulate running the load.
index = 0;
while (index < indexes_per_load) {
// Print out index value.
if ((index % 10) == 0) {
printf("load");
}
// Wait 1 second to simulate work.
sleep(seconds_per_index);
// Increment index.
index += 1;
}
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment