Esempio n. 1
0
void test_four(FILE *log,int NFILE,t_filenm fnm[],t_atoms *atoms,
	       t_inputrec *ir,rvec x[],rvec f[],rvec box,real charge[],
	       real phi_f[],real phi_s[],int nmol,t_commrec *cr,
	       bool bOld,bool bOldEwald)
{
  int  i;
  real energy;

  if (bOldEwald)  
    energy = do_ewald(log,ir,atoms->nr,x,f,charge,box,phi_f,cr,bOld);
  else
    energy = do_ewald_new(log,ir,atoms->nr,x,f,charge,box,phi_f,cr,bOld);
  
  /*symmetrize_phi(log,atoms->nr,phi_f,bVerbose);*/
    
  /* Plot the long range fourier solution in a matrix */    
  plot_phi(opt2fn("-elf",NFILE,fnm),box,atoms->nr,x,phi_f);
  print_phi(opt2fn("-of",NFILE,fnm),atoms->nr,x,phi_f);
  calc_ener(log,"Fourier",FALSE,nmol,atoms->nr,phi_f,charge,&atoms->excl);
  write_pqr(opt2fn("-pf",NFILE,fnm),atoms,x,phi_f,0.0/*1.5*box[XX]*/);
  pr_f("four-force",atoms->nr,f);
  
  /* Calc and plot the total potential */
  for(i=0; (i<atoms->nr); i++) {
    phi_f[i]+=phi_s[i];
    /*clear_rvec(f[i]);*/
  }
  calc_ener(log,"Fourier+SR",FALSE,nmol,atoms->nr,phi_f,charge,&atoms->excl);
}
Esempio n. 2
0
void conductDPBackward(int scanline,
                       int *phi,
                       int *pie_y,
                       int *pie_d,
                       int *dis,
                       int *no_igL,
                       int *no_igR,
                       int flag,
                       int scanline_interest)
{
   int y, deltaa;                   /* the match following (y_p, delta_p) */
   int y_p, delta_p;                /* the current match */
   int phi_new, phi_best;
   int pie_y_best, pie_d_best;
/*      printf("Starting...\n");  fflush(stdout); */

   for (delta_p = 0 ; delta_p <= g_maxdisp ; delta_p++)  {
      phi[(g_cols+g_slop)*scanline+(g_maxdisp + 1)*0+delta_p] = DEFAULT_COST + dis[(g_cols+g_slop)*scanline+(g_maxdisp + 1)*0+delta_p];
      pie_y[(g_cols+g_slop)*scanline+(g_maxdisp + 1)*0+delta_p] = FIRST_MATCH;
      pie_d[(g_cols+g_slop)*scanline+(g_maxdisp + 1)*0+delta_p] = FIRST_MATCH;
   }

   for (y = 1 ; y < g_cols ; y++)  {
      /* printf("y=%d\n", y);  fflush(stdout); */
      for (deltaa = 0 ; deltaa <= g_maxdisp ; deltaa++)  {

         phi_best = INF;

         for (delta_p = 0 ; delta_p <= g_maxdisp ; delta_p++)  {
            y_p = y - max(1, delta_p - deltaa + 1);
            if (y_p>=0) {
               if (deltaa==delta_p ||
                   (deltaa>delta_p && !no_igL[(g_cols+g_slop)*scanline+y+deltaa-1]) ||
                   (deltaa<delta_p && !no_igR[(g_cols+g_slop)*scanline+y_p+1])) {
                  phi_new = 
                     occ_pen * (deltaa != delta_p);
                     if (scanline==scanline_interest && y==12) {
                        printf("## phi_new=%d\n", phi_new);
                     }
                  if (flag>0 && scanline>0) {
                     int s = phi[(g_cols+g_slop)*scanline+(g_maxdisp + 1)*y_p+delta_p] +
                        phi[(g_cols+g_slop)*(scanline-1)+(g_maxdisp + 1)*y+deltaa];
                     if (scanline==scanline_interest && y==12) {
                        printf("## s=%d\n", s);
                     }
/*                     int n = 2; */
                     if (0 && deltaa>delta_p) {
                        int yy = y_p+1;
                        while (yy+delta_p<y+deltaa) {
                           if (yy<0 || yy>=g_cols+g_slop) printf("****yy=%d\n", yy);
                           assert(yy>=0 && yy<g_cols+g_slop);
                           assert(delta_p>=0 && delta_p<=g_maxdisp);
                           s += phi[(g_cols+g_slop)*(scanline-1)+(g_maxdisp + 1)*yy+delta_p];
                           /*                          n++; */
                           yy++;
                        }
                     } else if (0 && deltaa<delta_p) {
                        int yy = y_p+1;
                        while (yy<y) {
                           assert(yy>=0 && yy<g_cols+g_slop);
                           assert(delta_p>=0 && delta_p<=g_maxdisp);
                           s += phi[(g_cols+g_slop)*(scanline-1)+(g_maxdisp + 1)*yy+deltaa];
                           /* n++; */
                           yy++;
                        }                           
                           
/*                     while (d<delta_p) { */
                        /*                      d++; */
                        /*s += phi[scanline-1][y][d]; */
                        /*n++; */
                     }
/*                     phi_new += (phi[scanline][y_p][delta_p] + */
/*                         phi[scanline-1][y][deltaa])/2; */
                     phi_new += s;
                  } else {
                     phi_new += phi[(g_cols+g_slop)*scanline+(g_maxdisp + 1)*y_p+delta_p];
                  }
/*                  if (scanline==scanline_interest && y==549) printf("## delta=%2d, delta_p=%2d, phi_new=%d\n", deltaa, delta_p, phi_new); */
                     if (scanline==scanline_interest && y==12) {
                        printf("## phi_new=%d\n", phi_new);
                     }
                  if (phi_new < phi_best) {
         if (scanline==scanline_interest && y==12) printf("!! New Phi_best !!\n");
                     phi_best = phi_new;
                     pie_y_best = y_p;
                     pie_d_best = delta_p;
                  }
               }
            }
         }
         if (scanline==scanline_interest && y==12) printf("--## delta=%2d, phi_best=%d\n", deltaa, phi_best);
         phi[(g_cols+g_slop)*scanline+(g_maxdisp + 1)*y+deltaa] = phi_best +
            dis[(g_cols+g_slop)*scanline+(g_maxdisp + 1)*y+deltaa] - reward;

         /*     if (scanline == scanline_interest && y<15 && deltaa==4) { */
         /* printf("[%3d][%3d][%2d]:  phi=%d\n", */
         /*        scanline, y, deltaa, phi[(g_cols+g_slop)*scanline+(g_maxdisp + 1)*y+deltaa]); */
         /*} */
         pie_y[(g_cols+g_slop)*scanline+(g_maxdisp + 1)*y+deltaa] = pie_y_best;
         pie_d[(g_cols+g_slop)*scanline+(g_maxdisp + 1)*y+deltaa] = pie_d_best;
      }
   }
   
   if (scanline>0) {
      for (y=0 ; y<g_cols ; y++)
         for (deltaa=0 ; deltaa<=g_maxdisp ; deltaa++)
            phi[(g_cols+g_slop)*scanline+(g_maxdisp + 1)*y+deltaa] /= ((scanline-1)*g_cols+y);
   }
   
   if (scanline==scanline_interest) {
/*      print_phi(phi, scanline, 0, 50, 0, 14); */
      print_phi(phi, scanline, 0, 150, 0, 5);
   }
   
/*   normalize_phi(scanline, phi, scanline_interest); */
   
/*   if (scanline==scanline_interest) { */
/*      print_phi(phi, scanline, 0, 50, 0, 14); */
/*      print_phi(phi, scanline, 0, 150, 0, 5); */
/*   } */
   
/*      printf("Ending...\n");  fflush(stdout); */
}
void InstructionPrinter::do_BlockBegin(BlockBegin* x) {
  // print block id
  BlockEnd* end = x->end();
  output()->print("B%d ", x->block_id());

  // print flags
  bool printed_flag = false;
  if (x->is_set(BlockBegin::std_entry_flag)) {
    if (!printed_flag) output()->print("(");
    output()->print("S"); printed_flag = true;
  }
  if (x->is_set(BlockBegin::osr_entry_flag)) {
    if (!printed_flag) output()->print("(");
    output()->print("O"); printed_flag = true;
  }
  if (x->is_set(BlockBegin::exception_entry_flag)) {
    if (!printed_flag) output()->print("(");
    output()->print("E"); printed_flag = true;
  }
  if (x->is_set(BlockBegin::subroutine_entry_flag)) {
    if (!printed_flag) output()->print("(");
    output()->print("s"); printed_flag = true;
  }
  if (x->is_set(BlockBegin::parser_loop_header_flag)) {
    if (!printed_flag) output()->print("(");
    output()->print("LH"); printed_flag = true;
  }
  if (x->is_set(BlockBegin::backward_branch_target_flag)) {
    if (!printed_flag) output()->print("(");
    output()->print("b"); printed_flag = true;
  }
  if (x->is_set(BlockBegin::was_visited_flag)) {
    if (!printed_flag) output()->print("(");
    output()->print("V"); printed_flag = true;
  }
  if (printed_flag) output()->print(") ");

  // print block bci range
output()->print("[%d, %d]",x->bci(),(end==NULL?InvocationEntryBci:end->bci()));

  // print block successors
  if (end != NULL && end->number_of_sux() > 0) {
    output()->print(" ->");
    for (int i = 0; i < end->number_of_sux(); i++) {
      output()->print(" B%d", end->sux_at(i)->block_id());
    }
  }
  // print exception handlers
  if (x->number_of_exception_handlers() > 0) {
    output()->print(" (xhandlers ");
    for (int i = 0; i < x->number_of_exception_handlers();  i++) {
      if (i > 0) output()->print(" ");
      output()->print("B%d", x->exception_handler_at(i)->block_id());
    }
    output()->put(')');
  }

  // print dominator block
  if (x->dominator() != NULL) {
    output()->print(" dom B%d", x->dominator()->block_id());
  }

  // print predecessors and successors
  if (x->successors()->length() > 0) {
    output()->print(" sux:");
    for (int i = 0; i < x->successors()->length(); i ++) {
      output()->print(" B%d", x->successors()->at(i)->block_id());
    }
  }

  if (x->number_of_preds() > 0) {
    output()->print(" pred:");
    for (int i = 0; i < x->number_of_preds(); i ++) {
      output()->print(" B%d", x->pred_at(i)->block_id());
    }
  }

  if (!_print_phis) {
    return;
  }

  // print phi functions
  bool has_phis_in_locals = false;
  bool has_phis_on_stack = false;

  if (x->end() && x->end()->state()) {
    ValueStack* state = x->state();

    int i = 0;
    while (!has_phis_on_stack && i < state->stack_size()) {
      Value v = state->stack_at_inc(i);
      has_phis_on_stack = is_phi_of_block(v, x);
    }

    do {
      for (i = 0; !has_phis_in_locals && i < state->locals_size();) {
        Value v = state->local_at(i);
        has_phis_in_locals = is_phi_of_block(v, x);
        // also ignore illegal HiWords
        if (v && !v->type()->is_illegal()) i += v->type()->size(); else i ++;
      }
      state = state->caller_state();
    } while (state != NULL);

  }

  // print values in locals
  if (has_phis_in_locals) {
    output()->cr(); output()->print_cr("Locals:");

    ValueStack* state = x->state();
    do {
      for (int i = 0; i < state->locals_size();) {
        Value v = state->local_at(i);
        if (v) {
          print_phi(i, v, x); output()->cr();
          // also ignore illegal HiWords
          i += (v->type()->is_illegal() ? 1 : v->type()->size());
        } else {
          i ++;
        }
      }
      output()->cr();
      state = state->caller_state();
    } while (state != NULL);
  }

  // print values on stack
  if (has_phis_on_stack) {
    output()->print_cr("Stack:");
    int i = 0;
    while (i < x->state()->stack_size()) {
      int o = i;
      Value v = x->state()->stack_at_inc(i);
      if (v) {
        print_phi(o, v, x); output()->cr();
      }
    }
  }
}