/** Generate a new `IterMap` from the given information. */
Generate a new `IterMap` from the given information.
Generate a new ` IterMap ` from the given information .
pub fn new(dims: ImageDims, itertype: IterType, limit: usize) -> IterMap {
        let n_chunks = CHUNKS_PER_THREAD * *N_THREADS;
        let chunk_height = dims.ypix / n_chunks;
        let last_chunk_height = dims.ypix % n_chunks;
        let mut to_process: Vec<IterMapChunk> = Vec::new();
        let mut start_y: usize = 0;
        for _ in 0..n_chunks {
            let imc = IterMapChunk {
                dims,
                itertype: itertype.clone(),
                y_start: start_y,
                n_rows: chunk_height,
                last_limit: 0,
                data: Vec::new(),
            };
            to_process.push(imc);
            start_y += chunk_height;
        }
        if last_chunk_height > 0 {
            let imc = IterMapChunk {
                dims,
                itertype: itertype.clone(),
                y_start: start_y,
                n_rows: last_chunk_height,
                last_limit: 0,
                data: Vec::new(),
            };
            to_process.push(imc);
        }
        let n_chunks = to_process.len();
        let mut done_chunks: Vec<IterMapChunk> = Vec::with_capacity(n_chunks);
        let mut active_threads: usize = 0;
        let (tx, rx) = mpsc::channel::<IterMapChunk>();
        while done_chunks.len() < n_chunks {
            if active_threads < *N_THREADS {
                if let Some(mut imc) = to_process.pop() {
                    #[cfg(debug_assertions)]
                    println!(
                        "chunk -> (y_start: {}, n_rows: {}, pixels: {})",
                        imc.y_start,
                        imc.n_rows,
                        imc.data.len()
                    );
                    let txc = tx.clone();
                    thread::spawn(move || {
                        imc.iterate(limit);
                        txc.send(imc).unwrap();
                    });
                    active_threads += 1;
                }
            }
            if active_threads == *N_THREADS || to_process.is_empty() {
                let imc = rx.recv().unwrap();
                #[cfg(debug_assertions)]
                println!(
                    "<- chunk (y_start: {}, n_rows: {}, pixels: {})",
                    imc.y_start,
                    imc.n_rows,
                    imc.data.len()
                );
                active_threads -= 1;
                done_chunks.push(imc);
            }
        }
        done_chunks.sort_by_key(|imc| imc.y_start);
        IterMap {
            dims,
            itertype,
            limit,
            chunks: done_chunks,
        }
    }
pub fn new ( dims : ImageDims , itertype : IterType , limit : usize ) -> IterMap { let n_chunks = CHUNKS_PER_THREAD * * N_THREADS ; let chunk_height = dims . ypix / n_chunks ; let last_chunk_height = dims . ypix % n_chunks ; let mut to_process : Vec < IterMapChunk > = Vec :: new ( ) ; let mut start_y : usize = 0 ; for _ in 0 .. n_chunks { let imc = IterMapChunk { dims , itertype : itertype . clone ( ) , y_start : start_y , n_rows : chunk_height , last_limit : 0 , data : Vec :: new ( ) , } ; to_process . push ( imc ) ; start_y += chunk_height ; } if last_chunk_height > 0 { let imc = IterMapChunk { dims , itertype : itertype . clone ( ) , y_start : start_y , n_rows : last_chunk_height , last_limit : 0 , data : Vec :: new ( ) , } ; to_process . push ( imc ) ; } let n_chunks = to_process . len ( ) ; let mut done_chunks : Vec < IterMapChunk > = Vec :: with_capacity ( n_chunks ) ; let mut active_threads : usize = 0 ; let ( tx , rx ) = mpsc :: channel :: < IterMapChunk > ( ) ; while done_chunks . len ( ) < n_chunks { if active_threads < * N_THREADS { if let Some ( mut imc ) = to_process . pop ( ) { # [ cfg ( debug_assertions ) ] println ! ( " " imc y_start imc n_rows imc data len ( ) ) ; let txc = tx . clone ( ) ; thread :: spawn ( move | | { imc . iterate ( limit ) ; txc . send ( imc ) . unwrap ( ) ; } ) ; active_threads += 1 ; } } if active_threads == * N_THREADS || to_process . is_empty ( ) { let imc = rx . recv ( ) . unwrap ( ) ; # [ cfg ( debug_assertions ) ] println ! ( " " imc y_start imc n_rows imc data len ( ) ) ; active_threads -= 1 ; done_chunks . push ( imc ) ; } } done_chunks . sort_by_key ( | imc | imc . y_start ) ; IterMap { dims , itertype , limit , chunks : done_chunks , } }
Generate a new `IterMap` from the given information.
Generate a new ` IterMap ` from the given information .
dims
ImageDims
itertype
IterType
limit
usize