Skip to content

Commit

Permalink
Merge pull request #2040 from gforney/PART
Browse files Browse the repository at this point in the history
speed up particle loading by sorting tags in parallel
  • Loading branch information
gforney authored Sep 28, 2024
2 parents f731514 + b6cc368 commit a35313b
Show file tree
Hide file tree
Showing 15 changed files with 2,806 additions and 16 deletions.
65 changes: 64 additions & 1 deletion Source/smokeview/IOpart.c
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,44 @@ void GeneratePartHistograms(void){
}
}

#ifdef pp_SORT_TAGS
/* ------------------ SortPartTags ------------------------ */

void SortPartTags(partdata *parti){
int i;
part5data *datacopy_local;

datacopy_local = parti->data5;
for(i = 0; i < parti->ntimes; i++){
int class_index;

for(class_index = 0; class_index < parti->nclasses; class_index++){
qsort(datacopy_local->sort_tags, ( size_t )datacopy_local->npoints_file, 2*sizeof(int), CompareTags);
datacopy_local++;
}
}
}

/* ------------------ SortAllPartTags ------------------------ */

void *SortAllPartTags(void *arg){
int i;

INIT_PRINT_TIMER(timer_sortparttags);
for(i = 0; i < npartinfo; i++){
partdata *parti;

parti = partinfo + i;
if(parti->loaded == 0)continue;
SortPartTags(parti);
}
PRINT_TIMER(timer_sortparttags, "SortPartTags");
#ifdef pp_SORT_TAGS_BG
THREAD_EXIT(sorttags_threads);
#endif
}
#endif

/* ------------------ GetPartData ------------------------ */

void GetPartData(partdata *parti, int nf_all_arg, FILE_SIZE *file_size_arg){
Expand Down Expand Up @@ -1306,7 +1344,9 @@ void GetPartData(partdata *parti, int nf_all_arg, FILE_SIZE *file_size_arg){
sort_tags_local[2*j]=datacopy_local->tags[j];
sort_tags_local[2*j+1]=j;
}
#ifndef pp_SORT_TAGS
qsort( sort_tags_local, (size_t)nparts_local, 2*sizeof(int), CompareTags);
#endif
}
}
else{
Expand Down Expand Up @@ -1449,6 +1489,17 @@ partpropdata *GetPartProp(char *label){
return NULL;
}

/* ------------------ SetStreakShow ------------------------ */

void SetStreakShow(int show){
#ifdef pp_SORT_TAGS_BG
if(show == 1){
THREADcontrol(sorttags_threads, THREAD_JOIN);
}
#endif
streak5show = show;
}

/* ------------------ InitPartProp ------------------------ */

void InitPartProp(void){
Expand Down Expand Up @@ -2108,6 +2159,16 @@ void FinalizePartLoad(partdata *parti){
}
}
visParticles = 1;
#ifdef pp_SORT_TAGS
#ifdef pp_SORT_TAGS_BG
THREADrun(sorttags_threads);
if(runscript == 1 || streak5show == 1){
THREADcontrol(sorttags_threads, THREAD_JOIN);
}
#else
SortAllPartTags(NULL);
#endif
#endif

// generate histograms now rather than in the background if a script is running

Expand Down Expand Up @@ -2229,7 +2290,9 @@ FILE_SIZE ReadPart(char *file_arg, int ifile_arg, int load_flag, int *errorcode_
return 0.0;
}
CheckMemory;
INIT_PRINT_TIMER(timer_getpartdata);
GetPartData(parti, nf_all_local, &file_size_local);
PRINT_TIMER(timer_getpartdata, "GetPartData");
CheckMemory;
THREADcontrol(partload_threads, THREAD_LOCK);
parti->loaded = 1;
Expand Down Expand Up @@ -2258,7 +2321,7 @@ FILE_SIZE ReadPart(char *file_arg, int ifile_arg, int load_flag, int *errorcode_
if(parti->finalize == 1){
INIT_PRINT_TIMER(finalize_part);
FinalizePartLoad(parti);
PRINT_TIMER(finalize_part, "finalize particle time");
PRINT_TIMER(finalize_part, "FinalizePartLoad");
}
STOP_TIMER(load_time_local);
#ifndef pp_PARTFRAME
Expand Down
4 changes: 2 additions & 2 deletions Source/smokeview/glui_bounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6363,10 +6363,10 @@ void PartBoundCB(int var){
case STREAKLENGTH:
UpdateStreakValue(float_streak5value-0.001);
if(float_streak5value==0.0){
streak5show=0;
SetStreakShow(0);
}
else{
streak5show=1;
SetStreakShow(1);
}
updatemenu=1;
break;
Expand Down
4 changes: 2 additions & 2 deletions Source/smokeview/menus.c
Original file line number Diff line number Diff line change
Expand Up @@ -3901,14 +3901,14 @@ void ParticleStreakShowMenu(int value){

if(value==-1)return;
if(value==MENU_STREAK_HIDE){
streak5show=0;
SetStreakShow(0);
streak5step=0;
}
else if(value==MENU_STREAK_HEAD){
showstreakhead=1-showstreakhead;
}
else{
streak5show=1;
SetStreakShow(1);
streak5step=0;
rvalue=streak_rvalue[value];
UpdateStreakValue(rvalue-0.001);
Expand Down
2 changes: 2 additions & 0 deletions Source/smokeview/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#define pp_GPUTHROTTLE // pp_GPU directive must also be set
#endif
//#define pp_FDS // create a 1 mesh input file
#define pp_SORT_TAGS // sort particle tags after after particles are read in
#define pp_SORT_TAGS_BG // sort particle tags in background

#ifdef pp_FRAME // turn on each frame type if pp_FRAME is set
#define pp_BOUNDFRAME // turn on frame code for boundary files
Expand Down
6 changes: 6 additions & 0 deletions Source/smokeview/readsmv.c
Original file line number Diff line number Diff line change
Expand Up @@ -11882,6 +11882,12 @@ int ReadSMV_Configure(){
THREADrun(ffmpeg_threads);
PRINT_TIMER(timer_readsmv, "SetupFFMT");

#ifdef pp_SORT_TAGS_BG
if(sorttags_threads == NULL){
sorttags_threads = THREADinit(&n_sorttags_threads, &use_sorttags_threads, SortAllPartTags);
}
#endif

if(isosurface_threads == NULL){
isosurface_threads = THREADinit(&n_isosurface_threads, &use_isosurface_threads, SetupAllIsosurfaces);
}
Expand Down
4 changes: 4 additions & 0 deletions Source/smokeview/smokeheaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ EXTERNCPP void *ReadVolsmokeAllFramesAllMeshes2(void *arg);
EXTERNCPP void *SetupAllIsosurfaces(void *arg);
EXTERNCPP void *MtMergeSmoke3D(void *arg);
EXTERNCPP void UpdateGluiMergeSmoke(void);
#ifdef pp_SORT_TAGS
EXTERNCPP void *SortAllPartTags(void *arg);
#endif

//*** glui_bounds.cpp headers
EXTERNCPP int GLUIGetChopHide(char *label);
Expand Down Expand Up @@ -1115,6 +1118,7 @@ EXTERNCPP void SetSliceMax(int set_valmax, float valmax, char *buffer2);
EXTERNCPP void SetSliceBounds(int set_valmin, float valmin, int set_valmax, float valmax, char *buffer2);
EXTERNCPP void SetBoundBounds(int set_valmin, float valmin, int set_valmax, float valmax, char *buffer2);

EXTERNCPP void SetStreakShow(int show);
EXTERNCPP void GetPartColors(partdata *parti, int nlevels, int flag);
EXTERNCPP void GetBoundaryColors(float *t, int nt, unsigned char *it,
int settmin, float *tmin, int settmax, float *tmax,
Expand Down
6 changes: 6 additions & 0 deletions Source/smokeview/smokeviewvars.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ SVEXTERN int SVDECL(use_partload_threads, 1);
#endif
SVEXTERN threaderdata SVDECL(*partload_threads, NULL);

#ifdef pp_SORT_TAGS_BG
//*** sorttags
SVEXTERN int SVDECL(n_sorttags_threads, 1), SVDECL(use_sorttags_threads, 1);
SVEXTERN threaderdata SVDECL(*sorttags_threads, NULL);
#endif

//*** patchbounds
SVEXTERN int SVDECL(n_patchbound_threads, 1), SVDECL(use_patchbound_threads, 1);
SVEXTERN threaderdata SVDECL(*patchbound_threads, NULL);
Expand Down
14 changes: 5 additions & 9 deletions vistest/large/part/part.fds → vistest/large/part/part1gb.fds
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
&HEAD CHID='part' /
&HEAD CHID='part1gb' /

&MESH IJK=10,10,4, XB=0.0,1.0,0.0,1.0,0.0,0.4 /

&TIME T_END=60 /
&DUMP NFRAMES=550 /

&TIME T_END=55.0 /

&SURF ID='hot', GEOMETRY='SPHERICAL', HEAT_TRANSFER_COEFFICIENT=0., EMISSIVITY=1., TMP_FRONT=800, RADIUS=0.005 /

&PART ID='embers', SURF_ID='hot', SAMPLING_FACTOR=1, STATIC=T, QUANTITIES='PARTICLE TEMPERATURE', PROP_ID='ball shape' /

&PROP ID='ball shape', SMOKEVIEW_ID='SPHERE', SMOKEVIEW_PARAMETERS(1)='D=0.01' /

&INIT PART_ID='embers', N_PARTICLES=800000, XB=0.0,1.0,0.0,1.0,0.0,0.02 /
&INIT PART_ID='embers', N_PARTICLES=100000, XB=0.0,1.0,0.0,1.0,0.0,0.02 /

&VENT MB='ZMAX', SURF_ID='OPEN' /

&BNDF QUANTITY='GAUGE HEAT FLUX', CELL_CENTERED=T /
&BNDF QUANTITY='WALL TEMPERATURE', CELL_CENTERED=T /

&SLCF PBY=0.5, QUANTITY='RADIATION LOSS', CELL_CENTERED=T /
&SLCF PBY=0.5, QUANTITY='INTEGRATED INTENSITY', CELL_CENTERED=T /

&TAIL /
Loading

0 comments on commit a35313b

Please sign in to comment.