Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SoftwareSpeedUp

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.
Avatar for taxio taxio
July 27, 2018

 SoftwareSpeedUp

Avatar for taxio

taxio

July 27, 2018
Tweet

More Decks by taxio

Other Decks in Technology

Transcript

  1. ίϯύΠϥͰ࠷దԽ ˔ ΠϯςϧͷίϯύΠϥ Ὂ উखʹฒྻԽͯ͘͠ΕΔΒ͍͠ Ὂ ֶੜ͸ແྉͰखʹೖΕΒΕΔ ˔ ίϯύΠϥͷ࠷దԽΦϓγϣϯ Ὂ

    0ϝϞϦ΁ͷΞΫηεΛݮΒ͢ Ὂ 0΄ͱΜͲͷ࠷దԽΦϓγϣϯΛ༗ޮԽ Ὂ 00 JOMJOFGVODUJPOT
  2. $ݴޠ4JOHMF #include <stdio.h> #include <math.h> double get_coefficient(int i){ return i

    % 2 ? -1.0 : 1.0; } int main(int argc, char *argv[]){ printf("%d\n", argc); int i; double sum = 0.0; for(i=0; i<=100000000; i++){ sum += get_coefficient(i) / (2.0 * i + 1.0); } sum *= 4; printf("Ans:%.16f\n", sum); return 0; }
  3. $ݴޠ.VMUJ5ISFBE int main(void){ struct index idx[N_THREAD]; int i; int base

    = 100000000/N_THREAD; pthread_t threads[N_THREAD]; int rets[N_THREAD]; for(i=0; i<N_THREAD; i++){ idx[i].begin = i*base; idx[i].end = (i+1)*base; rets[i] = pthread_create(&threads[i], NULL, (void *)calc_thread, (void *)&idx[i]); } void *statuses[N_THREAD]; for(i=0; i<N_THREAD; i++){ rets[i] = pthread_join(threads[i], &statuses[i]); } double sum = 0.0; for(i=0; i<N_THREAD; i++){ sum += *(double *)statuses[i]; } printf("%.16f\n", sum); return 0; }
  4. 3VTUͰฒྻԽ use std::thread; fn calc(begin: i32, end: i32) -> f32{

    let mut sum = 0.0; for i in begin..end{ sum += if i % 2 == 0 {1.0} else {-1.0} / (2.0 * i as f32 + 1.0); } sum * 4.0 } const N_THREAD: i32 = 10; fn main() { let mut children = vec![]; let base = 100000000 / N_THREAD; for i in 0..N_THREAD{ children.push(thread::spawn(move || { calc(i*base, (i+1)*base) })); } let mut sum = 0.0; for c in children{ let ret = c.join().unwrap(); sum += ret; } println!("{}", sum); }
  5. 3VTUͷ։ൃ؀ڥʹ͍ͭͯ ˔ SVTUVQίϯύΠϥͷΠϯετʔϧؔ࿈πʔϧ ˔ SVTUJDίϯύΠϥ ˔ DBSHPϏϧυγεςϜύοέʔδϚωʔδϟ ˔ ΤσΟλܥ Ὂ

    +FU#SBJOTͷϓϥάΠϯ Ὂ ެ͕ࣜิ׬༻ͷϓϥάΠϯΛग़ͯ͠Δ ˗ SBDFS ˗ 74$PEFͱ͔7JNͰ΋Ͱ͖Δʂʂ