/*
 *  ticket-396.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::ticket-396 - Ensure that the number of threads cannot be changed after resolution.

Synopsis: (ticket-396) run -> NEST exits if test fails

Description: 
This ticket ensures that the number of threads cannot be changed if the resolution
differs from the default resolution.
 
Author: Hans Ekkehard Plesser, 2012-12-03
 */

(unittest) run
/unittest using

M_ERROR setverbosity

% The following two tests must fail for one of two reasons:
% 
% 1. NEST was built without OpenMP/Thread support. Then,
%    changing the number of threads either directly or
%    through total_num_virtual_procs must fail.
% 2. NEST was built with thread support. Then, changing
%    the number of threads after changing the resolution
%    must raise an error.

% test against changing local_num_threads
{ 
  ResetKernel
  /new_res 0 /resolution get 2 mul def
  /new_threads 0 /local_num_threads get 2 mul def
  0 << /resolution new_res >> SetStatus
  0 << /local_num_threads new_threads >> SetStatus
} fail_or_die

% test against changing total_num_virtual_procs
{ 
  ResetKernel
  /new_res 0 /resolution get 2 mul def
  /new_procs 0 /total_num_virtual_procs get 2 mul def
  0 << /resolution new_res >> SetStatus
  0 << /total_num_virtual_procs new_procs >> SetStatus
} fail_or_die


% The remaining tests require that the number of threads
% or virtual processes can be changed from within the
% running process; they check that the correct number
% of threads/VPs is set.
% These tests can therefore only run if NEST is threaded.

skip_if_not_threaded

% check that we can change either way before setting resolution
{ 
  ResetKernel
  /new_res 0 /resolution get 2 mul def
  /new_threads 0 /local_num_threads get 2 mul def
  0 << /local_num_threads new_threads >> SetStatus
  0 << /resolution new_res >> SetStatus
  0 /resolution get new_res eq
  0 /local_num_threads get new_threads eq
  and
} assert_or_die

{ 
  ResetKernel
  /new_res 0 /resolution get 2 mul def
  /new_procs 0 /total_num_virtual_procs get 2 mul def
  0 << /total_num_virtual_procs new_procs >> SetStatus
  0 << /resolution new_res >> SetStatus
  0 /resolution get new_res eq
  0 /total_num_virtual_procs get new_procs eq
  and
} assert_or_die

% test that we can set in single call
{ 
  ResetKernel
  /new_res 0 /resolution get 2 mul def
  /new_threads 0 /local_num_threads get 2 mul def
  0 << /local_num_threads new_threads
       /resolution new_res >> SetStatus
  0 /resolution get new_res eq
  0 /local_num_threads get new_threads eq
  and
} assert_or_die

{ 
  ResetKernel
  /new_res 0 /resolution get 2 mul def
  /new_procs 0 /total_num_virtual_procs get 2 mul def
  0 << /total_num_virtual_procs new_procs 
       /resolution new_res >> SetStatus
  0 /resolution get new_res eq
  0 /total_num_virtual_procs get new_procs eq
  and
} assert_or_die

endusing
