/*
 *  test_gsd.sli
 *
 *  This file is part of NEST.
 *
 *  Copyright (C) 2004 The NEST Initiative
 *
 *  NEST is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  NEST is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with NEST.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

 /* BeginDocumentation
Name: testsuite::test_gsd- Test global spike detector with pure MPI parallelism

Synopsis: nest_indirect test_gsd.sli -> -

Description:
This script tests the gsd spike detector scheme by comparing the
output of 2 poisson generators on 2 MPI procs run in conventional mode
to the output on 3 MPI procs run in gsd mode.

Author: Kunkel, Schmidt
FirstVersion: February 2014
*/


(unittest) run
/unittest using


[2 3]
{
    NumProcesses /num_mpi_procs Set
    num_mpi_procs 3 eq
    {
	1 SetNumRecProcesses
    }
    if

    0 <<
        /total_num_virtual_procs num_mpi_procs
	/rng_seeds [1 0 num_mpi_procs add] Range		
    >> SetStatus
    
    
    /parrot_neuron 2 Create pop
    /spike_detector 1 Create /sd Set
    /poisson_generator 1 Create /pg Set
    pg
    <<
   	/rate 200.0
    >> SetStatus

    [pg] [1 2] Connect
    [1 2] [sd] Connect

    100. Simulate
    sd GetStatus /local get %%% Necessary because a spike detector does not have an events entry in its status dict if it is not local
    {
	/ev sd /events get def
     	ev keys { /k Set ev dup k get cva k exch put } forall
     	ev
    }
    {
     	/ev << /senders [] /times [] >> def
     	 ev
    } ifelse
} distributed_process_invariant_events_assert_or_die
 
