05.04.2015 Views

BSP/CGM Algorithms - USP

BSP/CGM Algorithms - USP

BSP/CGM Algorithms - USP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Prefix Sum - <strong>BSP</strong><br />

// Passo 1. Inicilizacao<br />

bsplib_saveargs(&argc, &argv);<br />

bsplib_init(<strong>BSP</strong>LIB_STDPARAMS, &bsp); // iniciliza o pub<br />

size = bsp_nprocs(&bsp); // numero de tarefas<br />

rank = bsp_pid(&bsp); // identificacao da tarefa<br />

// Passo 2. Envie os dados as tarefas filhos<br />

bsp_push_reg(&bsp, &numelem, sizeof(int));<br />

bsp_get(&bsp, 0, &numelem, 0, &numelem, sizeof(int));<br />

bsp_sync(&bsp);<br />

bsp_pop_reg(&bsp, &numelem);<br />

tam = (int) numelem/size;<br />

// Passo 3. Receba em SubVetor rank*tam-esima parte de VetorDados<br />

bsp_push_reg(&bsp, VetorDados, numelem*sizeof(int));<br />

bsp_get(&bsp, 0, VetorDados, rank*tam*sizeof(int), SubVetor, tam*sizeof(int));<br />

bsp_sync(&bsp);<br />

bsp_pop_reg(&bsp, VetorDados);<br />

// Passo 4. Calcule a Soma em cada tarefa<br />

for (i = 0; i < tam; i++)<br />

SomaP = SomaP + SubVetor[i];<br />

soma = SomaP;<br />

19/24

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!