/*
 *  test_gsd_distribution.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_distribution - Test global spike detector with pure MPI parallelism

Synopsis: nest_indirect test_gsd_distribution.sli -> -

Description:
Tests if global spike detectors are equally distributed among virtual
recording processes. The script creates 6 Spike detectors on 1,2 and 3
recording processes, respectively, and checks if they are equally
distributed.

Author: Kunkel, Schmidt
FirstVersion: April 2014
*/


(unittest) run
/unittest using


[2 3 4]
{
    NumProcesses /num_mpi_procs Set
    num_mpi_procs 1 sub SetNumRecProcesses
    
    0 <<
        /total_num_virtual_procs num_mpi_procs
    >> SetStatus
    
   
    /iaf_neuron 1 Create pop
    /spike_detector 2 Create pop
    /iaf_neuron 1 Create pop
    /spike_detector 2 Create pop 
    /iaf_neuron 1 Create pop
    /spike_detector 2 Create pop 

    
    Rank 0 gt
    {
    	[2 3 5 6 8 9] /sd Set
    	0 /num_sd Set
    	sd
    	{
    	    /n Set
    	    n GetStatus /local get
    	    {
    		num_sd 1 add /num_sd Set
    	    } if
    	} forall
	
    	num_sd cvd sd length num_mpi_procs 1 sub div cvd eq
	
    }
    {
    	true
    } ifelse
 
} distributed_collect_assert_or_die
 
