; This function is for use with multi-processing (i.e. splitting an job ; over multiple CPUs). It is meant to be used in conjunction with ; mp_get_entries_to_process. ; ; The function takes as input a filename, and the total number of processes ; you will be running. For example, if you will have 2 processes on 6 machines, ; set total_procs=12. Set filename to something unique, so you won't overwrite ; it yourself when running other tests, and so no one else will overwrite it ; during your test. ; ; The function returns the process number (1..total_procs) for the process which ; called it. ; ; Example of how to use in your code: ; ; ; Call this early on, so you can start your processes right after one another. ; total_procs = 12 ; my_procnum = mp_get_procnum('.my_mp_file', total_procs) ; ... ; ... ; obs = ..... ; An array of observations to process. ; ; mp_get_entries_to_process(my_procnum, total_procs, n_elements(obs), start_index, end_index) ; ; ; Cut down the array to what this process will work on. ; obs = obs[start_index:end_index] ; function mp_get_procnum, mp_filename, total_procs ; Open the file which has the process number stamp. OPENR, 1, mp_filename, error=error ; Handle case when file does not (yet) exist. if (error ne 0) then begin ; File probably doesn't exist yet. This is procnum 1. CLOSE, 1 this_procnum = 1 ; Write this process number to the file. OPENW, 1, mp_filename printf, 1, this_procnum CLOSE, 1 GOTO, OUT endif ; Read the old proc num (last process stamped this here). prev_procnum = INT(0) readf, 1, prev_procnum CLOSE, 1 ; Check for an old file. if (prev_procnum eq total_procs) then begin ; Start fresh. this_procnum = 1 ; Write this process number to the file. OPENW, 1, mp_filename printf, 1, this_procnum CLOSE, 1 GOTO, OUT endif ; Increase the procnum by 1. this_procnum = prev_procnum + 1 ; Stamp new proc num to the file. OPENW, 1, mp_filename printf, 1, this_procnum CLOSE, 1 OUT: ; Print out the procnum to help the user avoid mistakes. print, 'I am process', strcompress(string(this_procnum)), '.' wait, 1 return, this_procnum end