Skip to content

Commit

Permalink
Added fix to the partitioning
Browse files Browse the repository at this point in the history
The choose_part_count function that is important for creating an irregular mesh partitioning wasn't behaving as expected. Due to operator precedence the values of R and Q weren't being decremented, instead the operation was being applied to the pointer itself and hence odd things were happening. Fixed with some simple bracketing.
  • Loading branch information
jadickson committed Aug 11, 2018
1 parent 4b48fa9 commit ca43ec5
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions macsio/macsio_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include <string.h>
#include <time.h>


/*!
\brief Support functions for Perlin noise
@{
Expand Down Expand Up @@ -1024,6 +1023,7 @@ make_mesh_chunk(int chunkId, int ndims, int const *dims, double const *bounds, c
}

static int latest_rand_num = 0;
static int run_seed = 0;

static int choose_part_count(int K, int mod, int *R, int *Q)
{
Expand All @@ -1035,24 +1035,24 @@ static int choose_part_count(int K, int mod, int *R, int *Q)
{
if (*R > 0)
{
*R--;
(*R)--;
}
else if (*Q > 0)
{
retval = K+1;
*Q--;
(*Q)--;
}
}
else
{
if (*Q > 0)
{
*Q--;
(*Q)--;
}
else if (*R > 0)
{
retval = K;
*R--;
(*R)--;
}
}
return retval;
Expand Down Expand Up @@ -1156,7 +1156,15 @@ MACSIO_DATA_GenerateTimeZeroDumpObject(json_object *main_obj, int *rank_owning_c
rank = 0;
chunk = 0;

srand(0xDeadBeef); /* initialize for choose_part_count */
/* If we haven't set a seed for the run then take this from the clock.
* This should allow us to randomise the decomposition between runs but
* still use this overloaded function to identify chunk ownership within
* a single run
*/
if (run_seed == 0){
run_seed = time(NULL);
}
srand(run_seed); /* initialize for choose_part_count */
latest_rand_num = rand();
parts_on_this_rank = choose_part_count(K,mod,&R,&Q);
for (ipart = 0; ipart < nx_parts; ipart++)
Expand Down

0 comments on commit ca43ec5

Please sign in to comment.