nest-simulator icon indicating copy to clipboard operation
nest-simulator copied to clipboard

NEST behaves incorrectly or fails when connecting sliced layers while using MPI

Open heplesser opened this issue 1 year ago • 0 comments

This issue is based on a recent post on the NEST User Mailing List. Thanks to Miriam Kempter for reporting it!

A minimal reproducer with two different cases triggering errors in different locations is

import nest

# segfaults in neurons[pick].spatial / slice_positions_if_sliced_nc() with -np 3
# num_neurons = 7
# pick = 6

# with mask, vector access violation in Connect() / FreeLayer< D >::get_position() with -np 3 
num_neurons = 5
pick = 3

neurons = nest.Create(model='parrot_neuron', n=num_neurons,
                      positions=nest.spatial.free(
                                  pos=nest.random.uniform(min=-1, max=1),
                                  num_dimensions=2,
                                  edge_wrap=False))

print(neurons[pick].spatial)

nest.Connect(neurons[pick], neurons, {'rule': 'pairwise_bernoulli', 'p': 1.0,
                                      'mask': {'circular': {'radius': 2}}
                                          })

# expected output: source pick+1 connected once to each neuron
print(nest.GetConnections())

First issue

In the first case (with 7 neurons), the call to neurons[pick].spatial leads to use of an invalid access here:

https://github.com/nest/nest-simulator/blob/8e85268ca512e0f509240fb5ef06f62a4e61a67e/nestkernel/nest.cpp#L438

To protect against uncaught invalid access, one should add in

https://github.com/nest/nest-simulator/blob/8e85268ca512e0f509240fb5ef06f62a4e61a67e/sli/tokenarray.h#L186-L196

an

 assert( index_is_valid( i ) );

Second issue

In the other case (with 5 neurons), the Connect() call in presence of a mask leads to and out-of-bounds exception here

https://github.com/nest/nest-simulator/blob/8e85268ca512e0f509240fb5ef06f62a4e61a67e/nestkernel/free_layer.h#L302

which calls

https://github.com/nest/nest-simulator/blob/8e85268ca512e0f509240fb5ef06f62a4e61a67e/nestkernel/free_layer.h#L270-275

Analysis

The most critical parts are probably

  • https://github.com/nest/nest-simulator/blob/8e85268ca512e0f509240fb5ef06f62a4e61a67e/nestkernel/nest.cpp#L420
  • The various ways of initializing NodeCollection::const_iterator, especially from NodeCollection::MPI_local_begin() and NodeCollection::local_begin() and the increment operators for the iterator.

The logic of these in relation to slicing and MPI needs review.

heplesser avatar Feb 20 '24 08:02 heplesser