use rayon::prelude::*; pub trait SyncStrategy: Sync + Send { fn apply_sync(packed_phase: u64, sync_pull: u64, mask_2bit: u64) -> u64; } pub struct PaletteAStrategy; impl SyncStrategy for PaletteAStrategy { #[inline(always)] fn apply_sync(packed_phase: u64, sync_pull: u64, _mask: u64) -> u64 { // `--1` 상태(0b11)를 전체 32개 뉴런에 올바르게 적용하기 위한 비트 연산 수정 let pull_11 = sync_pull | (sync_pull << 1); (packed_phase & !pull_11) | pull_11 } } /// 싱글 스레드 동기화 (기존) pub fn synchronize_phases_fast(packed_phases: &mut [u64], context_signal: u64) { let mask_2bit = 0x5555555555555555; for phase in packed_phases.iter_mut() { let phase_difference = *phase ^ context_signal; let sync_pull = (phase_difference & mask_2bit) >> 1; *phase = T::apply_sync(*phase, sync_pull, mask_2bit); } } /// [신규] 멀티코어 CPU 100% 점유 동기화 (Rayon 적용) pub fn synchronize_phases_par(packed_phases: &mut [u64], context_signal: u64) { let mask_2bit = 0x5555555555555555; packed_phases.par_iter_mut().for_each(|phase| { let phase_difference = *phase ^ context_signal; let sync_pull = (phase_difference & mask_2bit) >> 1; *phase = T::apply_sync(*phase, sync_pull, mask_2bit); }); }