Skip to content

Commit 56ffa52

Browse files
committed
optimize cache
remove temporary variables from workspace
1 parent af69e68 commit 56ffa52

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

functions/run_heating_simulations.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
% convert absorption to Nepers/((rad/s)^y m)
2323
a0_np = db2neper(kwave_medium.alpha_coeff, kwave_medium.alpha_power);
2424
alpha_np = a0_np.*w.^kwave_medium.alpha_power;
25+
clear w a0_np;
2526

2627
% alternative simplified conversion dB to Nepers
2728
% alpha_np = (100 * kwave_medium.alpha_coeff .* (parameters.transducer.source_freq_hz/10^6)^kwave_medium.alpha_power)/8.686;
@@ -30,6 +31,7 @@
3031
p = gather(abs(sensor_data.p_max_all));
3132
source.Q = (alpha_np .* p.^2) ./ (kwave_medium.density .* kwave_medium.sound_speed); % Heat delivered to the system (W/m3)
3233
source.T0 = kwave_medium.temp_0; %parameters.thermal.temp_0; % Initial temperature distribution
34+
clear alpha_np p;
3335

3436
% split temp_0 off from kWave_medium
3537
kwave_medium = rmfield(kwave_medium, 'temp_0');

single_subject_pipeline.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@
9696
%% Extra settings needed for better usability
9797
warning('off','MATLAB:prnRenderer:opengl'); % suppress unneccessary warnings from export_fig when running without OpenGL
9898

99+
% output GPU information (if requested)
100+
if strcmp(parameters.code_type, 'cuda') || strcmp(parameters.code_type, 'matlab_gpu')
101+
gpuDevice()
102+
end
103+
99104
%% Start of simulations
100105
% Creates an output file to which output is written at a later stage
101106
output_pressure_file = fullfile(parameters.output_dir,sprintf('sub-%03d_%s_output_table%s.csv', ...
@@ -117,7 +122,8 @@
117122
t1_info = niftiinfo(filename_t1);
118123
t1_grid_step_mm = t1_info.PixelDimensions(1);
119124
focal_distance_t1 = norm(parameters.focus_pos_t1_grid - parameters.transducer.pos_t1_grid);
120-
parameters.expected_focal_distance_mm = focal_distance_t1 * t1_grid_step_mm;
125+
parameters.expected_focal_distance_mm = focal_distance_t1 * t1_grid_step_mm;
126+
clear filename_t1 t1_info focal_distance_t1 t1_grid_step_mm;
121127
end
122128

123129
% if there is no specification of usepseudoCT, go for default of 0
@@ -428,6 +434,12 @@
428434
[kwaveDiffusion, time_status_seq, maxT, focal_planeT, maxCEM43, focal_planeCEM43]= ...
429435
run_heating_simulations(sensor_data, kgrid, kwave_medium, sensor, source, parameters, trans_pos_final);
430436

437+
% apply gather in case variables are GPU arrays
438+
maxT = gather(maxT);
439+
focal_planeT = gather(focal_planeT);
440+
maxCEM43 = gather(maxCEM43);
441+
focal_planeCEM43 = gather(focal_planeCEM43);
442+
431443
save(filename_heating_data, 'kwaveDiffusion','time_status_seq',...
432444
'heating_window_dims','sensor','maxT','focal_planeT','maxCEM43','focal_planeCEM43','-v7.3');
433445

0 commit comments

Comments
 (0)