@@ -93,8 +93,6 @@ struct SetupThreads {
9393 nrn_threads_create (config.num_threads );
9494 create_interleave_info ();
9595 int num_cells_remaining{config.num_cells }, total_cells{};
96- // Hack so stateful produce_* functions have the same state for all solver implementations.
97- auto local_config = config;
9896 for (auto ithread = 0 ; ithread < nrn_nthread; ++ithread) {
9997 auto & nt = nrn_threads[ithread];
10098 // How many cells to distribute on this thread, trying to get the right
@@ -107,12 +105,13 @@ struct SetupThreads {
107105 auto const padded_size = nrn_soa_padded_size (nt.end , 0 );
108106 // Allocate one big block because the GPU data transfer code assumes this.
109107 nt._ndata = padded_size * 4 ;
110- nt._data = new double [ nt._ndata ] ;
108+ nt._data = static_cast < double *>( emalloc_align ( nt._ndata * sizeof ( double ))) ;
111109 auto * vec_rhs = (nt._actual_rhs = nt._data + 0 * padded_size);
112110 auto * vec_d = (nt._actual_d = nt._data + 1 * padded_size);
113111 auto * vec_a = (nt._actual_a = nt._data + 2 * padded_size);
114112 auto * vec_b = (nt._actual_b = nt._data + 3 * padded_size);
115- auto * parent_indices = (nt._v_parent_index = new int [padded_size]);
113+ auto * parent_indices =
114+ (nt._v_parent_index = static_cast <int *>(emalloc_align (padded_size * sizeof (int ))));
116115 // Magic value to check against later.
117116 std::fill (parent_indices, parent_indices + nt.end , magic_index_value);
118117 // Put all the root nodes first, then put the other segments
@@ -128,10 +127,10 @@ struct SetupThreads {
128127 for (auto icell = 0 ; icell < nt.ncell ; ++icell) {
129128 for (auto iseg = 0 ; iseg < config.num_segments_per_cell ; ++iseg) {
130129 auto const global_index = get_index (icell, iseg);
131- vec_a[global_index] = local_config .produce_a (icell, iseg);
132- vec_b[global_index] = local_config .produce_b (icell, iseg);
133- vec_d[global_index] = local_config .produce_d (icell, iseg);
134- vec_rhs[global_index] = local_config .produce_rhs (icell, iseg);
130+ vec_a[global_index] = config .produce_a (icell, iseg);
131+ vec_b[global_index] = config .produce_b (icell, iseg);
132+ vec_d[global_index] = config .produce_d (icell, iseg);
133+ vec_rhs[global_index] = config .produce_rhs (icell, iseg);
135134 // 0th element is the root node, which has no parent
136135 // other elements are attached in a binary tree configuration
137136 // | 0 |
@@ -187,9 +186,9 @@ struct SetupThreads {
187186 ~SetupThreads () {
188187 delete_nrnthreads_on_device (nrn_threads, nrn_nthread);
189188 for (auto & nt: *this ) {
190- delete[] std::exchange (nt._data , nullptr );
189+ free_memory ( std::exchange (nt._data , nullptr ) );
191190 delete[] std::exchange (nt._permute , nullptr );
192- delete[] std::exchange (nt._v_parent_index , nullptr );
191+ free_memory ( std::exchange (nt._v_parent_index , nullptr ) );
193192 }
194193 destroy_interleave_info ();
195194 nrn_threads_free ();
@@ -377,11 +376,7 @@ auto random_config() {
377376 ToyModelConfig config{};
378377 config.produce_a = [g = gen, d = std::normal_distribution{1.0 , 0.1 }](int icell,
379378 int iseg) mutable {
380- auto const v = d (g);
381- if (icell == 0 && iseg == 0 ) {
382- std::cout << " returning a=" << v << " for (0, 0)" << std::endl;
383- }
384- return v;
379+ return d (g);
385380 };
386381 config.produce_b = [g = gen, d = std::normal_distribution{7.0 , 0.2 }](int , int ) mutable {
387382 return d (g);
0 commit comments