/***********************************************************/
/*   da.cc                                                 */
/***********************************************************/

#include "da.h"

int ipe, npe;

void hostname(char *buf, int size){
  int len;
  FILE *fp;
  fp = popen("hostname", "r");
  fgets(buf, size, fp);
  len = strlen(buf);
  buf[len-1] = '\0';
  pclose(fp);
}


int main(int args, char** argv){
  assert(args == 3);
  ipe = atoi(argv[1]);
  npe = atoi(argv[2]);
  
  char hn[100];
  hostname(hn, 100);
  
  da::Manager *dam = new da::Manager(hn);
  int x_size = 1000;
  int y_size = 1000;
  
  if(ipe == 0){
    da::Fraction *f = new CGMatrix(dam, new da::IndexSet(0, x_size, 0, y_size), new da::IndexSet(0, x_size, 0, y_size), 
                                   new da::IndexSet(0, 1, 0, 1), new da::IndexSet(0, x_size, 0, y_size));
    dam->registerFraction(1, f);
  } else {
    //    sleep(1);
    dam->join(1, new da::IndexSet(0, x_size, 0, y_size));
  }


  
  if(ipe == 0){
    da::Msg *m = new da::Msg(da::Msg::_RMI, 1, da::Method::_calc);
    m->p_int(1);
    m->p_int((int)CGMatrix::_none);
    m->send(new da::IndexSet(0, x_size, 0, y_size));
    delete(m);
  }


  sleep(1000);
  delete(dam);
  return 0;
}


