Skip to content

Commit

Permalink
Added the inital work on making this parallel.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswailes committed Feb 5, 2014
1 parent 6d68769 commit 2e6084e
Show file tree
Hide file tree
Showing 1,042 changed files with 127,202 additions and 17 deletions.
8 changes: 4 additions & 4 deletions Makefile
Expand Up @@ -4,17 +4,17 @@
#Description: Makefile for plpsolve.

CC = gcc
CFLAGS = -Wall -O3 -fopenmp
LFLAGS =
CFLAGS = -Wall -O3 -fopenmp -fPIC -g
LFLAGS = -pthread

PROGRAM = plpsolve

SOURCE = dictionary.c input.c kernels.c main.c matrix.c output.c util.c
SOURCE = bloom.c dictionary.c hashes.c input.c kernels.c list.c main.c matrix.c output.c util.c work_queue.c worker.c
EXECS = plpsolve

all: $(EXECS)

plpsolve: $(SOURCE)
$(PROGRAM): $(SOURCE)
$(CC) $(CFLAGS) $(LFLAGS) -o $(PROGRAM) $(SOURCE)

.PHONY: clean
Expand Down
107 changes: 107 additions & 0 deletions bloom.c
@@ -0,0 +1,107 @@
/*
* Author: Chris Wailes <chris.wailes@gmail.com>
* Project: Chris's Awesome Standard Library
* Description: A simple Bloom Filter implementation that was initially
taken from here: http://en.literateprograms.org/Bloom_filter_%28C%29
*/

// Standard Includes
#include <limits.h>
#include <stdarg.h>
#include <string.h>
#include <sys/types.h>

// Project Includes
#include "bloom.h"
#include "util.h"

// Macros
#define SETBIT(a, n) (a[n / CHAR_BIT] |= (1 << (n % CHAR_BIT)))
#define GETBIT(a, n) (a[n / CHAR_BIT] & (1 << (n % CHAR_BIT)))

#define BYTES_FOR_BITS(bits) ((bits + CHAR_BIT - 1) / CHAR_BIT)

// Global Variables

// Functions

/*
* Size represents the length of the filter in BITS.
*/
bloom_t* bloom_create(size_t size, uint nfuncs, ...) {
bloom_t* bloom;
va_list arg_list;

if ((bloom = bloom_new()) == NULL) {
return NULL;
}

if (!bloom_init(bloom, size, nfuncs, arg_list)) {
free(bloom);
return NULL;
}

return bloom;
}

void bloom_destroy(bloom_t* bloom) {
free(bloom->bits);
free(bloom->funcs);
free(bloom);
}

/*
* Size represents the length of the filter in BITS.
*/
bool bloom_init(bloom_t* bloom, size_t size, uint nfuncs, ...) {
va_list arg_list;

if ((bloom->bits = (unsigned char*) calloc(BYTES_FOR_BITS(size), sizeof(char))) == NULL) {
return FALSE;
}

if ((bloom->funcs = (bloomhash_t*) calloc(nfuncs, sizeof(bloomhash_t))) == NULL) {
free(bloom->bits);
return FALSE;
}

bloom->bits_size = size;
bloom->nfuncs = nfuncs;

va_start(arg_list, nfuncs);
while (nfuncs-- > 0) {
bloom->funcs[nfuncs] = va_arg(arg_list, bloomhash_t);
}
va_end(arg_list);

return TRUE;
}

bloom_t* bloom_new(void) {
return (bloom_t*) malloc(sizeof(bloom_t));
}

void bloom_add(bloom_t* bloom, const unsigned char* data, uint length) {
uint index;

for (index = bloom->nfuncs; index-- > 0;) {
SETBIT(bloom->bits, bloom->funcs[index](data, length) % bloom->bits_size);
}
}

bool bloom_check(bloom_t* bloom, const unsigned char* data, uint length) {
uint index;

for (index = bloom->nfuncs; index-- > 0;) {
if(!(GETBIT(bloom->bits, bloom->funcs[index](data, length) % bloom->bits_size))) return FALSE;
}

return TRUE;
}

#include <stdio.h>

void bloom_reset(bloom_t* bloom) {
memset(bloom->bits, 0, BYTES_FOR_BITS(bloom->bits_size));
}

55 changes: 55 additions & 0 deletions bloom.h
@@ -0,0 +1,55 @@
/*
* Author: Chris Wailes <chris.wailes@gmail.com>
* Project: Chris's Awesome Standard Library
* Description: Declarations for a simple Bloom Filter implementation that
was initially taken from here: http://en.literateprograms.org/Bloom_filter_%28C%29
*/

#ifndef BLOOM_H
#define BLOOM_H

// Standard Includes
#include <stdlib.h>
#include <sys/types.h>

// Project Includes
#include "hashes.h"
#include "util.h"

// Macros

// 0.25MiB == 2^18 bytes == 2097152 bits
#define BLOOM_SIZE_SMALL 2097152

// 0.50MiB == 2^19 bytes == 4194304 bits
#define BLOOM_SIZE_MEDIUM 4194304

// 1.00MiB == 2^20 bytes == 8388608 bits
#define BLOOM_SIZE_LARGE 8388608

#define DEFAULT_BLOOM_FILTER bloom_create(BLOOM_SIZE_MEDIUM, 3, bernstein_hash, sax_hash, sdbm_hash)

// Types

typedef unsigned int (*bloomhash_t)(const unsigned char*, uint);

typedef struct {
size_t bits_size;
unsigned char* bits;

uint nfuncs;
bloomhash_t* funcs;
} bloom_t;

// Functions

bloom_t* bloom_create(size_t size, uint nfuncs, ...);
void bloom_destroy(bloom_t* bloom);
bool bloom_init(bloom_t* bloom, size_t size, uint nfuncs, ...);
bloom_t* bloom_new(void);

void bloom_add(bloom_t* bloom, const unsigned char* data, uint length);
bool bloom_check(bloom_t* bloom, const unsigned char* data, uint length);
void bloom_reset(bloom_t* bloom);

#endif
20 changes: 13 additions & 7 deletions dictionary.c
Expand Up @@ -83,6 +83,15 @@ void dict_add_split_vars(dict_t* dict, uvars_t uvars) {
dict->split_vars = uvars.indices;
}

dict_t* dict_clone(dict_t* orig) {
dict_t* clone;

clone = dict_new(orig->num_vars, orig->num_cons);
dict_copy(clone, orig);

return clone;
}

void dict_copy(dict_t* new_dict, dict_t* orig_dict) {
uint row_index;

Expand Down Expand Up @@ -309,15 +318,14 @@ bool dict_init(dict_t** dict) {
// Return False if we didn't do any initialization.
if ((uvars.size + iset.size) == 0) {
return FALSE;

}

/*
* Set the appropriate dictionary reference and return True if we had to
* split some variables.
*/
if (iset.size == 0) {
(*dict) = stage1_dict;
*dict = stage1_dict;
return TRUE;
}

Expand Down Expand Up @@ -389,7 +397,7 @@ bool dict_init(dict_t** dict) {
}

// Set the appropriate dictionary reference and return True.
(*dict) = stage2_dict;
*dict = stage2_dict;
return TRUE;
}

Expand Down Expand Up @@ -570,8 +578,6 @@ dict_t* dict_pivot(dict_t* dict, uint var_index, uint con_index, rest_t new_rest
dict->objective2[col_index] += coefficient * tmp_row[col_index];
}

if (dict->objective2[col_index] == INFINITY) printf("Infinity: %u, (%g) %g * %g\n", col_index, swap, coefficient, tmp_row[col_index]);

if (FPN_IS_ZERO(dict->objective2[col_index])) dict->objective2[col_index] = 0.0;
}
}
Expand Down Expand Up @@ -986,10 +992,10 @@ void dict_view_answer(const dict_t* dict) {

num_orig_vars = dict->num_vars - dict->num_aux_vars - dict->num_split_vars;

printf("\t z = %- 7.3f\n", dict->objective_value);
printf("\t z = %g\n", dict->objective_value);

for (var_index = 1; var_index <= num_orig_vars; ++var_index) {
snprintf(buffer, 10, "x%u", var_index);
printf("\t%4s = %f\n", buffer, dict_get_var_value_by_label(dict, var_index));
printf("\t%4s = %g\n", buffer, dict_get_var_value_by_label(dict, var_index));
}
}
1 change: 1 addition & 0 deletions dictionary.h
Expand Up @@ -85,6 +85,7 @@ typedef struct {

void dict_add_aux_vars(dict_t* dict, iset_t iset);
void dict_add_split_vars(dict_t* dict, uvars_t uvars);
dict_t* dict_clone(dict_t* orig_dict);
void dict_copy(dict_t* new_dict, dict_t* orig_dict);
void dict_flip_rest(dict_t* dict, uint var_index, rest_t new_rest);
void dict_free(dict_t* dict);
Expand Down
46 changes: 46 additions & 0 deletions hashes.c
@@ -0,0 +1,46 @@
/*
* Author: Chris Wailes <chris.wailes@gmail.com>
* Project: Chris's Awesome Standard Library
* Description: Simple, non-cryptographically secure, hashes.
*/

// Standard Includes
#include <sys/types.h>

// Project Includes

// Macros

// Global Variables

// Functions

uint bernstein_hash(const unsigned char* data, uint length) {
uint hash = 0;

while (length-- > 0) {
hash = 33 * hash + *data++;
}

return hash;
}

uint sax_hash(const unsigned char* data, uint length) {
uint hash = 0;

while (length-- > 0) {
hash ^= (hash << 5) + (hash >> 2) + (unsigned char)*data++;
}

return hash;
}

uint sdbm_hash(const unsigned char* data, uint length) {
uint hash = 0;

while (length-- > 0) {
hash = (unsigned char)*data++ + (hash << 6) + (hash << 16) - hash;
}

return hash;
}
25 changes: 25 additions & 0 deletions hashes.h
@@ -0,0 +1,25 @@
/*
* Author: Chris Wailes <chris.wailes@gmail.com>
* Project: Chris's Awesome Standard Library
* Description: Simple, non-cryptographically secure, hashes.
*/

#ifndef HASHES_H
#define HASHES_H

// Standard Includes
#include <sys/types.h>

// Project Includes

// Macros

// Types

// Functions

uint bernstein_hash(const unsigned char* data, uint length);
uint sax_hash(const unsigned char* data, uint length);
uint sdbm_hash(const unsigned char* data, uint length);

#endif
23 changes: 23 additions & 0 deletions kernels.c
Expand Up @@ -10,6 +10,7 @@
// Project Includes
#include "dictionary.h"
#include "kernels.h"
#include "worker.h"

// Global Variables

Expand Down Expand Up @@ -73,3 +74,25 @@ dict_t* general_simplex_kernel(dict_t* dict) {

return dict;
}

dict_t* kernel_select(dict_t* dict) {
switch (cfg.pmode) {
case PTHREADS:
dict = pthreads_kernel(dict);
break;

case AUTO:
case OMP:
case NONE:
default:
dict = general_simplex_kernel(dict);
break;
}

return dict;
}

inline dict_t* pthreads_kernel(dict_t* dict) {
return workers_manager(dict);
}

2 changes: 2 additions & 0 deletions kernels.h
Expand Up @@ -13,5 +13,7 @@
#define PROF_Y_THRESHOLD 10

dict_t* general_simplex_kernel(dict_t* dict);
dict_t* kernel_select(dict_t* dict);
dict_t* pthreads_kernel(dict_t* dict);

#endif

0 comments on commit 2e6084e

Please sign in to comment.