Homework in Bulk-Synchronous Parallel Computation Model
-------------------------------------------------------

Exercise 1
----------

Study the following program. What is its output, if there are 2 processors 
available.

#include <stdio.h>
#include <bsp.h>

int main(){
  int x,y;

  bsp_begin(bsp_nprocs());
  x=y=2*bsp_pid();
  y++;
  bsp_push_reg(bsp_pid()==0?&x:&y,sizeof(int));
  bsp_sync();

  if (bsp_pid()==0)
     bsp_put(1,&x,&x,0,sizeof(int));
  printf("[%d] x= %d, y=%d\n",bsp_pid(),x,y);
  bsp_sync();

  bsp_pop_reg(bsp_pid()==0?&x:&y);
  printf("[%d] x= %d, y=%d\n",bsp_pid(),x,y);
  bsp_end();
  return 0;
}

Exercise 2
----------

What does the following program do? What is the output?

#include <stdio.h>
#include <bsp.h>

int main(void) {
   int r;

   bsp_begin(bsp_nprocs());
   r=bsp_pid();

   printf("[%d]: r=%d\n",bsp_pid(),r);
   bsp_push_reg(&r,sizeof(int));
   bsp_sync();

   bsp_get((bsp_pid()+1)%bsp_nprocs(),&r,0,&r,sizeof(int));
   bsp_sync();
   printf("[%d]: r=%d\n",bsp_pid(),r);
   bsp_end();
}


Useful References and Hints
--------------------------
1. Manual of BSP at http://www.bsp-worldwide.org/implmnts/oxtool/man/
2. Study the slides 28-40 of the presentation