Skip to content

Commit

Permalink
merged CCP with master
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadenSmith committed Mar 4, 2016
2 parents 06cf4f4 + 0b49ff7 commit 76a667a
Show file tree
Hide file tree
Showing 8 changed files with 492 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Binary file IO now supported.
* Better handled missing input files.
* Added CREDITS.md
* Chains-on-chains partition available

1.1.1
=====
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ endif()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

file(GLOB SPLATT_SOURCES src/*.c ${MPI_SOURCES})
file(GLOB SPLATT_SOURCES src/*.c src/ccp/*.c ${MPI_SOURCES})

# Generate splatt library
add_subdirectory(lib)
Expand Down
182 changes: 182 additions & 0 deletions src/ccp/ccp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@


/******************************************************************************
* INCLUDES
*****************************************************************************/

#include "ccp.h"
#include "../timer.h"


/******************************************************************************
* PRIVATE FUNCTIONS
*****************************************************************************/

static idx_t nprobes = 0;


/**
* @brief Perform a linear search on an array for a value.
*
* @param weights The array to search.
* @param left The lower bound to begin at.
* @param right The upper (exclusive) bound of items.
* @param target The target value.
*
* @return The index j, where weights[j] <= target && weights[j+1] > target.
*/
static idx_t p_linear_search(
idx_t const * const weights,
idx_t const left,
idx_t const right,
idx_t const target)
{
for(idx_t x=left; x < right-1; ++x) {
if(weights[x+1] > target) {
return x;
}
}

return right;
}


/**
* @brief Perform a binary search on an array for a value.
*
* @param weights The array to search.
* @param left The lower bound to begin at.
* @param right The upper (exclusive) bound of items.
* @param target The target value.
*
* @return The index j, where weights[j] <= target && weights[j+1] > target.
*/
static idx_t p_binary_search(
idx_t const * const weights,
idx_t left,
idx_t right,
idx_t const target)
{
while((right - left) > 8) {
idx_t mid = left + ((right - left) / 2);

if(weights[mid] <= target && weights[mid+1] > target) {
return mid;
}

if(weights[mid] < target) {
left = mid + 1;
} else {
right = mid;
}
}

return p_linear_search(weights, left, right, target);
}



static idx_t p_eps_rb_partition_1d(
idx_t * const weights,
idx_t const nitems,
idx_t * const parts,
idx_t const nparts,
idx_t const eps)
{
idx_t lower = weights[nitems-1] / nparts;
idx_t upper = weights[nitems-1];

do {
idx_t mid = lower + ((upper - lower) / 2);
if(lprobe(weights, nitems, parts, nparts, mid)) {
upper = mid;
} else {
lower = mid+1;
}
} while(upper > lower + eps);

return upper;
}




/******************************************************************************
* PUBLIC FUNCTIONS
*****************************************************************************/

idx_t partition_1d(
idx_t * const weights,
idx_t const nitems,
idx_t * const parts,
idx_t const nparts)
{
timer_start(&timers[TIMER_PART]);
prefix_sum_inc(weights, nitems);

nprobes = 0;

/* use recursive bisectioning with 0 tolerance to get exact solution */
idx_t bottleneck = p_eps_rb_partition_1d(weights, nitems, parts, nparts, 0);

timer_stop(&timers[TIMER_PART]);
return bottleneck;
}



bool lprobe(
idx_t const * const weights,
idx_t const nitems,
idx_t * const parts,
idx_t const nparts,
idx_t const bottleneck)
{
idx_t p=0;
parts[p++] = 0;
idx_t bsum = bottleneck;

idx_t const wtotal = weights[nitems-1];

idx_t step = nitems / nparts;
while(p < nparts && bsum < wtotal) {
while(step < nitems && weights[step] < bsum) {
step += nitems / nparts;
}
parts[p] = p_binary_search(weights, step - (nitems/nparts), SS_MIN(step, nitems),
bsum);
bsum = weights[parts[p]] + bottleneck;
++p;
}

parts[p] = nitems;

++nprobes;
return bsum >= wtotal;
}



void prefix_sum_inc(
idx_t * const weights,
idx_t const nitems)
{
for(idx_t x=1; x < nitems; ++x) {
weights[x] += weights[x-1];
}
}



void prefix_sum_exc(
idx_t * const weights,
idx_t const nitems)
{
idx_t saved = weights[0];
weights[0] = 0;
for(idx_t x=1; x < nitems; ++x) {
idx_t const tmp = weights[x];
weights[x] = weights[x-1] + saved;
saved = tmp;
}
}
58 changes: 58 additions & 0 deletions src/ccp/ccp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#ifndef SPLATT_CCP_CCP_H
#define SPLATT_CCP_CCP_H

#include "../base.h"


/******************************************************************************
* INCLUDES
*****************************************************************************/
#include <stdbool.h>




/******************************************************************************
* PUBLIC FUNCTIONS
*****************************************************************************/

#define partition_1d splatt_partition_1d
idx_t partition_1d(
idx_t * const weights,
idx_t const nitems,
idx_t * const parts,
idx_t const nparts);


bool lprobe(
idx_t const * const weights,
idx_t const nitems,
idx_t * const parts,
idx_t const nparts,
idx_t const bottleneck);


#define prefix_sum_inc splatt_prefix_sum_inc
/**
* @brief Compute an inclusive prefix sum: [3, 4, 5] -> [3, 7, 12].
*
* @param weights The numbers to sum.
* @param nitems The number of items in 'weights'.
*/
void prefix_sum_inc(
idx_t * const weights,
idx_t const nitems);


#define prefix_sum_exc splatt_prefix_sum_exc
/**
* @brief Compute an exclusive prefix sum: [3, 4, 5] -> [0, 3, 7].
*
* @param weights The numbers to sum.
* @param nitems The number of items in 'weights'.
*/
void prefix_sum_exc(
idx_t * const weights,
idx_t const nitems);

#endif
2 changes: 0 additions & 2 deletions src/mpi/mpi_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "../util.h"



/******************************************************************************
* API FUNCTONS
*****************************************************************************/
Expand Down Expand Up @@ -279,7 +278,6 @@ static sptensor_t * p_rearrange_by_part(
}



static void p_find_my_slices_1d(
idx_t ** const ssizes,
idx_t const nmodes,
Expand Down
1 change: 1 addition & 0 deletions src/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static char const * const timer_names[] = {
[TIMER_MATMUL] = "MAT MULT",
[TIMER_ATA] = "MAT A^TA",
[TIMER_MATNORM] = "MAT NORM",
[TIMER_PART] = "PART1D",
[TIMER_MISC] = "MISC",
#ifdef SPLATT_USE_MPI
[TIMER_MPI] = "MPI",
Expand Down
1 change: 1 addition & 0 deletions src/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ typedef enum
TIMER_ATA,
TIMER_MATNORM,
TIMER_IO,
TIMER_PART,
TIMER_LVL2, /* LEVEL 2 */
#ifdef SPLATT_USE_MPI
TIMER_MPI,
Expand Down
Loading

0 comments on commit 76a667a

Please sign in to comment.