Changeset 412

Show
Ignore:
Timestamp:
07/15/08 12:52:03 (1 month ago)
Author:
apdavison
Message:

Ticket #104 points out that if compatible_output is False and there is an existing file with the same name, then Recorder.write() appends to the file, rather than overwriting it. I can't see any reason for this behaviour and so have changed it, but if this breaks your code, let me know. (Arguably if the file already exists the code should raise an Exception, but this needs to be done throughout the code base and so I have not implemented it yet - see #51).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/nest2/__init__.py

    r409 r412  
    160160        user_filename = file or self.filename 
    161161        nest_filename = _merge_files(self._device, gather) 
    162        if num_processes() > 1: 
     162        if num_processes() > 1: 
    163163            user_filename += '.%d' % rank() 
    164164        if compatible_output: 
    165165            # We should do the post processing (i.e the compatible output) in a distributed 
    166            # manner to speed up the thing. The only problem that will arise is the headers,  
    167            # that should be taken into account to be really clean. Otherwise, if the # symbol 
    168            # is escaped while reading the file, there is no problem 
     166            # manner to speed up the thing. The only problem that will arise is the headers,  
     167            # that should be taken into account to be really clean. Otherwise, if the # symbol 
     168            # is escaped while reading the file, there is no problem 
    169169           recording.write_compatible_output(nest_filename, user_filename, Recorder.formats[self.variable],self.population, get_time_step()) 
    170170        else: 
    171             system_line = 'cat %s >> %s' % (nest_filename, user_filename) 
     171            system_line = 'cat %s > %s' % (nest_filename, user_filename) 
    172172            os.system(system_line) 
    173        if gather == True and num_processes()> 1: 
    174            root_file = file or self.filename 
    175            for node in xrange(num_processes()): 
    176                if rank()==0: 
    177                    node_file = root_file + '.%d' % node  
    178                    if os.path.exists(node_file): 
    179                        system_line = 'cat %s >> %s' % (node_file, root_file) 
    180                        os.system(system_line) 
    181                        system_line = 'rm %s' %node_file 
    182                        os.system(system_line) 
     173        if gather == True and num_processes() > 1: 
     174            root_file = file or self.filename 
     175            for node in xrange(num_processes()): 
     176                if rank()==0: 
     177                    node_file = root_file + '.%d' % node  
     178                    if os.path.exists(node_file): 
     179                        system_line = 'cat %s >> %s' % (node_file, root_file) 
     180                        os.system(system_line) 
     181                        system_line = 'rm %s' % node_file 
     182                        os.system(system_line) 
    183183        # don't want to remove nest_filename at this point in case the user wants to access the data 
    184184        # a second time (e.g. with both getSpikes() and printSpikes()), but we should 
     
    528528            os.remove(nest_filename) 
    529529    #if gather and len(node_list) > 1: 
    530        ##if rank() == 0: 
     530        ##if rank() == 0: 
    531531        #raise Exception("gather not yet implemented") 
    532532    return merged_filename 
     
    877877        Returns the mean number of spikes per neuron. 
    878878        """ 
    879          
    880        ## Routine to give an average firing rate over all the threads/nodes 
    881        ## This is a rough approximation, because in fact each nodes is only multiplying  
    882        ## the frequency of the recorders by the number of processes. To do better, we need a MPI 
    883        ## package to send informations to node 0. Nevertheless, it works for threaded mode 
    884        node_list = range(nest.GetStatus([0], "total_num_virtual_procs")[0]) 
    885        n_spikes  = 0 
    886        for node in node_list: 
    887            nest.sps(self.recorders['spikes']._device[0]) 
    888            nest.sr("%d GetAddress %d append" %(self.recorders['spikes']._device[0], node)) 
    889            nest.sr("GetStatus /n_events get") 
    890            n_spikes += nest.spp() 
     879         
     880        ## Routine to give an average firing rate over all the threads/nodes 
     881        ## This is a rough approximation, because in fact each nodes is only multiplying  
     882        ## the frequency of the recorders by the number of processes. To do better, we need a MPI 
     883        ## package to send informations to node 0. Nevertheless, it works for threaded mode 
     884        node_list = range(nest.GetStatus([0], "total_num_virtual_procs")[0]) 
     885        n_spikes  = 0 
     886        for node in node_list: 
     887            nest.sps(self.recorders['spikes']._device[0]) 
     888            nest.sr("%d GetAddress %d append" %(self.recorders['spikes']._device[0], node)) 
     889            nest.sr("GetStatus /n_events get") 
     890            n_spikes += nest.spp() 
    891891        n_rec = len(self.recorders['spikes'].recorded) 
    892892        return float(n_spikes)/n_rec