Skip to content

Commit

Permalink
Allocate extra memory for map rebinning.
Browse files Browse the repository at this point in the history
Changing multithreading scheme for smf_rebinmap1.c requires some extra
memory. Each accumulator map is now nw times longer so that each thread
can accumulate into its own map. Instead of simply pointing to output maps
on first chunk, now need to do a memcpy on the first chunk (only).
  • Loading branch information
gmarsden committed Oct 28, 2013
1 parent c18c687 commit 1e26781
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions applications/smurf/libsmf/smf_iteratemap.c
Expand Up @@ -127,6 +127,7 @@
* TIMJ: Tim Jenness (JAC, Hawaii)
* DSB: David Berry (JAC, Hawaii)
* COBA: Coskun Oba (UoL)
* AGM: Gaelen Marsden (UBC)
* {enter_new_authors_here}
* History:
Expand Down Expand Up @@ -414,6 +415,8 @@
* 2013-7-23 (DSB):
* Do not converge until any initial iterations that skip the AST
* model have been done.
* 2013-10-25 (AGM):
* Allocate extra memory for maps for alternate rebinning scheme
* {enter_further_changes_here}
* Notes:
Expand Down Expand Up @@ -1310,23 +1313,17 @@ void smf_iteratemap( ThrWorkForce *wf, const Grp *igrp, const Grp *iterrootgrp,
if( contchunk == 0 ) {
/* For the first continuous chunk, calculate the map
in-place */
thismap = map;
thishits = hitsmap;
thisqual = mapqual;
thisvar = mapvar;
thisweight = weights;
mapweights = astCalloc( msize, sizeof(*mapweights) );
mapweightsq = astMalloc( msize*sizeof(*mapweightsq) );
thisweightsq = mapweightsq;
} else if( contchunk == 1 ) {
/* Subsequent continuous chunks are done in new map arrays and
then added to the first */
thismap = astCalloc( msize, sizeof(*thismap) );
thishits = astCalloc( msize, sizeof(*thishits) );
thisqual = astCalloc( msize, sizeof(*thisqual) );
thisvar = astCalloc( msize, sizeof(*thisvar) );
thisweight = astCalloc( msize, sizeof(*thisweight) );
thisweightsq = astCalloc( msize, sizeof(*thisweightsq) );

/* submaps for multithread rebinning -- each thread needs its own map.
Requires copying onto input maps on first contchunk */
thismap = astCalloc( nw*msize, sizeof(*thismap) );
thisweight = astCalloc( nw*msize, sizeof(*thisweight) );
thisweightsq = astCalloc( nw*msize, sizeof(*thisweightsq) );
thisvar = astCalloc( nw*msize, sizeof(*thisvar) );
thishits = astCalloc( nw*msize, sizeof(*thishits) );
thisqual = astCalloc( nw*msize, sizeof(*thisqual) );
}

/* Concat everything in this contchunk into a single smfArray. Note
Expand Down Expand Up @@ -2901,6 +2898,18 @@ void smf_iteratemap( ThrWorkForce *wf, const Grp *igrp, const Grp *iterrootgrp,
chunk. */
chunkweight = smf_chunkweight( res[0]->sdata[0], keymap,
contchunk, status );

/* on first chunk, copy thismap onto map
subsquent chunks get added below */
if( contchunk == 0 ) {
memcpy( map, thismap, msize*sizeof(*map) );
memcpy( weights, thisweight, msize*sizeof(*weights) );
memcpy( mapweightsq, thisweightsq, msize*sizeof(*mapweightsq) );
memcpy( mapvar, thisvar, msize*sizeof(*mapvar) );
memcpy( hitsmap, thishits, msize*sizeof(*hitsmap) );
memcpy( mapqual, thisqual, msize*sizeof(*mapqual) );
}

if( ncontchunks > 1 ) {
msgOut( " ", FUNC_NAME ": Adding map estimated from this continuous"
" chunk to total", status);
Expand Down

0 comments on commit 1e26781

Please sign in to comment.