Beispiel #1
0
int main(void)
{
	start_clock("fibo");
	recursive_fibonacci_number(33);
	stop_clock("fibo");

	start_clock("fibo2");
	iterative_fibonacci_number(33);
	stop_clock("fibo2");


	clock_report();
	return 0;
}
Beispiel #2
0
void room_update( void )
{
//  action_data*   action;
//  area_data*       area;
//  char_data*        rch;
//  room_data*       room;
  struct timeval   start;
  
  gettimeofday( &start, NULL );

  /*
  for( area = area_list; area != NULL; area = area->next ) 
    for( room = area->room_first; room != NULL; room = room->next ) {
      for( rch = room->people; rch != NULL && IS_NPC( rch );
        rch = rch->next_in_room );
      for( action = room->action; action != NULL; action = action->next ) 
        if( ( ( rch != NULL && action->trigger == TRIGGER_RANDOM )
          || action->trigger == TRIGGER_RANDOM_ALWAYS )
          && number_range( 0, 999 ) < action->value ) {
          var_room = room; 
          var_ch     = NULL;
          var_victim = NULL;
          var_mob    = NULL; 
          execute( action );
	  }
      }  
  */

  pulse_time[ TIME_RNDM_ACODE ] = stop_clock( start );  
     
  return;
}
Beispiel #3
0
int main(int argc, char* argv[]) {
    int i, j;
    int n = (SIZE);
    double A[(SIZE) * (SIZE)] = {0};
    double *L = NULL;
    FILE *fp = NULL;
    char filename[150];

    sprintf(filename, "%s/matrices/%d", PATH, SIZE);
    fp = fopen(filename, "r");
    if (fp == NULL) {
        return 1;
    }

    for (i = 0; i < n * n; ++i) {
        fscanf(fp, "%lf", A + i);  
    }

    start_clock();
    start_papi();
    L = cholesky(A, n);
    stop_papi();
    stop_clock();

    double checksum = 0.0;
    for (i = 0; i < n; ++i) {
        for (j = 0; j < n; ++j) {
            checksum += i + j + L[INDEX(i, j)];
        }
    }

    printf("Size: %d\n", n);
    printf("Checksum: %lf\n", checksum);
    return 0;
}
Beispiel #4
0
void executor_test(string_t description, function func)
{
    pre_executor_test(description);
    start_clock();
    func();
    stop_clock();
    post_executor_test(get_elapsed_time());
}
Beispiel #5
0
int main(int argc, char** argv)
{
  double one_gb = 1024*1024*1024;
  double num_gb;
  int size;
  int* T;
  int* SA;
  FILE* f;
  int c, j;
  error_t err;

  if( argc == 1 ) {
    printf("Usage: %s <num_gb> [input_file] [input_file] ...\n", argv[0]);
    return -1;
  }
  sscanf(argv[1], "%lf", &num_gb);
  printf("Will run test with %lf GB\n", num_gb);

  size = num_gb * one_gb;

  printf("Allocating memory (size=%i)\n", size);
  T = malloc((size+4)*sizeof(int));
  assert(T);
  SA = malloc(size*sizeof(int));
  assert(SA);

  // read in some input files.
  j = 0;
  for( int i = 2; i < argc && j < size; i++ ) {
    printf("Reading %s\n", argv[i]);
    f = fopen(argv[i], "r");
    assert(f);
    while( EOF != (c = fgetc(f)) &&
           j < size ) {
      T[j++] = c;
    }
    fclose(f);
  }
  if( j < size ) {
    // make some random data
    printf("Making random data\n");
    for( int i = j; i < size; i++ ) {
      T[i] = 1 + (rand() & 0xff);
    }
  }

  printf("Suffix sorting\n");
  // sort it.
  start_clock();
  err = suffixArray(T, SA, size, 256);
  die_if_err(err);
  stop_clock();
  print_timings("Suffix Sort Bytes", size);

  return 0;
}
Beispiel #6
0
void target(void* y, unsigned long count)
{
    arg_t* arg = (arg_t*) y;

    mpz_t x;
    mpz_init(x);

    mpz_poly_t in1, in2, out;
    mpz_poly_init(in1);
    mpz_poly_init(in2);
    mpz_poly_init(out);

    fmpz_poly_t in1f, in2f, outf;
    fmpz_poly_init2(in1f, arg->length1, (arg->bits1-1)/FLINT_BITS+1);
    fmpz_poly_init2(in2f, arg->length2, (arg->bits2-1)/FLINT_BITS+1);
    _fmpz_poly_stack_init(outf, arg->length1 + arg->length2 - 1,
                          in1f->limbs + in2f->limbs + 1);

    for (unsigned long i = 0; i < arg->length1; i++)
    {
        mpz_urandomb(x, randstate, arg->bits1);
        mpz_poly_set_coeff(in1, i, x);
    }
    mpz_poly_to_fmpz_poly(in1f, in1);

    for (unsigned long i = 0; i < arg->length2; i++)
    {
        mpz_urandomb(x, randstate, arg->bits2);
        mpz_poly_set_coeff(in2, i, x);
    }
    mpz_poly_to_fmpz_poly(in2f, in2);

    start_clock(0);

    if (arg->which)
    {
        for (unsigned long i = 0; i < count; i++)
            _fmpz_poly_mul_karatsuba(outf, in1f, in2f);
    }
    else
    {
        for (unsigned long i = 0; i < count; i++)
            mpz_poly_mul_karatsuba(out, in1, in2);
    }

    stop_clock(0);

    _fmpz_poly_stack_clear(outf);
    fmpz_poly_clear(in2f);
    fmpz_poly_clear(in1f);

    mpz_poly_clear(out);
    mpz_poly_clear(in2);
    mpz_poly_clear(in1);
    mpz_clear(x);
}
Beispiel #7
0
void update_handler( void )
{
  static int       pulse_area;
  static int     pulse_mobile;
  static int   pulse_violence;
  static int      pulse_point;
  static int       pulse_room;
  struct timeval        start;  

  gettimeofday( &start, NULL );

  event_update( );
  delete_list( extracted );

  if( --pulse_area <= 0 ) {
    pulse_area = number_range( PULSE_AREA/2, 3*PULSE_AREA/2 );
    area_update( );
    }

  if( --pulse_mobile <= 0 ) {
    pulse_mobile = PULSE_MOBILE;
    action_update( );
    auction_update( );
    regen_update( );
    time_update( );
    }

  if( --pulse_point <= 0 ) {
    pulse_point = number_range( PULSE_TICK/2, 3*PULSE_TICK/2 );
    char_update( );
    obj_update( );
    }

  if( --pulse_room <= 0 ) {
    pulse_room = number_range( PULSE_ROOM/2, 3*PULSE_ROOM/2 );
    room_update( );
    w3_who( );
    }

  if( --pulse_violence <= 0 ) {
    pulse_violence = PULSE_VIOLENCE;
    update_queue( );
    }

  pulse_time[ TIME_UPDATE ] = stop_clock( start );  
}
Beispiel #8
0
void char_update( void )
{   
  struct timeval   start;
  int i;
  
  gettimeofday( &start, NULL );

  for( i = 0; i < mob_list; i++ )
    update( mob_list[i] );
   
  for( i = 0; i < player_list; i++ )
    update( player_list[i] );

  pulse_time[ TIME_CHAR_LOOP ] = stop_clock( start );  

  return;
}
Beispiel #9
0
EXPORT	void	resolve_collision(
	Front	*front)
{
	INTERFACE *intfc = front->interf;
	CROSS *cr,*cross;
	C_CURVE *cc;
	int i;
	SURFACE **s;
	int c_type;
	char fname[100];
	int count = 0;
	double *x;

	start_clock("intersection");
	intersections(intfc,&cross,NO);
	stop_clock("intersection");
	if (cross == NULL) return;
	for (i = 0, cr = cross; cr != NULL; ++i, cr = cr->next)
	{
	    cc = cr->c_curve;
	    sprintf(fname,"cross-%d",count);
	    gview_plot_c_curve(cc,i,fname);
	    s = cc->s;
	    c_type = collision_type(intfc,s);
	    switch (c_type)
	    {
	    case FABRIC_RIGID_COLLISION:
		fabric_rigid_collision(front,cc);
		break;
	    case FABRIC_FABRIC_COLLISION:
		(void) printf("FABRIC_FABRIC_COLLISION not implemented!\n");
		continue;
	    case RIGID_RIGID_COLLISION:
		(void) printf("RIGID_RIGID_COLLISION not implemented!\n");
		clean_up(ERROR);
	    default:
		(void) printf("Unknown collision!\n");
		clean_up(ERROR);
	    }
	}
}	/* end resolve_collision */
Beispiel #10
0
void area_update( void )
{
  area_data*        area;
  room_data*        room;
  struct timeval   start;
  bool              save  = TRUE;

  gettimeofday( &start, NULL );

  for( int i = 0; i < max_clan; i++ ) 
    if( clan_list[i]->modified )
      save_clans( clan_list[i] );

  for( area = area_list; area != NULL; area = area->next ) {
    if( ++area->age < 15 && ( area->nplayer != 0 || area->age < 5 ) )
      continue;

    for( room = area->room_first; room != NULL; room = room->next )
      if( !player_in_room( room ) ) {
        reset_room( room );
        save_room_items( room );
        }

    area->age = number_range( 0, 3 );

    if( save && area->modified ) {
      save_area( area ); 
      save = FALSE;
      }
    }
  
  shop_update( );

  pulse_time[ TIME_RESET ] = stop_clock( start );

  return;
}
Beispiel #11
0
EXPORT int tangnt_advance_front2d(
	float    dt,
	float    *dt_frac,
	Front    *front,
	Front    **newfront,
	POINTER  wave)
{
	CURVE      *tempc,*newc;
	CURVE	   **c;
	NODE 	   *tempn,*newn;
	INTERFACE  *tempintfc;
	bool	   stat;
        bool       sav_copy;
	int        status = GOOD_STEP;
	long       intfc_modified;
	const char *fname = "tangnt_advance_front2d()";

	debug_print("front","Entered %s(step %d time %g dt %g)\n",fname,
	        	        front->step,front->time,dt);

	if ( front->interf == NULL || front->interf->nodes == NULL )
	    return return_advance_front(front,newfront,GOOD_STEP,fname);

        /* 050703 added, The interface regularization is performed here. */
        /* In advance_front2d(), these functions are called after
           normal_scatter_front, we call them here */ 
        delete_small_loops(*newfront); 

	stat = consistent_propagated_loop_orientations(dt,dt_frac,*newfront,wave);
	if(debugging("tangnt_advance_front2d"))
	    printf("In tangnt_advance_front2d() for patch %d\n", front->patch_number);
	if (stat == NO)
	{
	    (void) printf("WARNING in tangnt_advance_front2d(), "
		          "Inconsistent orientation of propagated loop "
	                  "detected after point and node propagations");
            if (pp_numnodes() > 1)
                (void) printf(" on processor %d\n",pp_mynode());
            else
                (void) printf("\n");
            status = MODIFY_TIME_STEP; 
            goto sync_prop_stat2;  
	}
        delete_exterior_curves(*newfront,front->interf);  
        intfc_delete_very_short_bonds(*newfront);
        stat = intfc_delete_fold_back_bonds(*newfront);
        if(stat == FUNCTION_FAILED)
        {
            (void) printf("WARNING in tangnt_advance_front2d(), "
                          "intfc_delete_fold_back_bonds() loop "
                          "detected error");
            if (pp_numnodes() > 1)
                (void) printf(" on processor %d\n",pp_mynode());
            else
                (void) printf("\n");
            status = MODIFY_TIME_STEP; 
            goto sync_prop_stat2;  
        } 
        delete_small_loops(*newfront); 
        /* 060303 added */ 
        measure_front(*newfront);
         
        /* Make Temp Interface for Second/Tangential Propagation */

        interpolate_intfc_states((*newfront)->interf) = YES;   
	set_node_doubly_linked_list((*newfront)->interf);
	if (front->snd_node_propagate || front->tan_curve_propagate) 
	{
	    start_clock("snd_copy_interface");
	    print_storage("before snd_copy_interface","ADV_storage");
	    tempintfc = (*newfront)->interf;
	    set_size_of_intfc_state(size_of_state(tempintfc));
	    set_add_to_correspond_list(YES);

            /* 060303, added copy_interface flag */
            sav_copy = copy_intfc_states();
            set_copy_intfc_states(YES);

	    (*newfront)->interf = copy_interface(tempintfc);
	    copy_hypersurface_flags((*newfront)->interf);
	    interpolate_intfc_states((*newfront)->interf) = YES;

            /* 060303, added copy_interface flag */
            set_copy_intfc_states(sav_copy);
	    print_storage("after snd_copy_interface","ADV_storage");
	    stop_clock("snd_copy_interface");
	}

        /* Second Propagation for the States Around the Nodes */

        if (front->snd_node_propagate)
        {
            start_clock("snd_node_propagate");
            if (debugging("front"))
                (void) printf("Second Loop over Nodes\n");

            tempn = first_node(tempintfc);
            newn = first_node((*newfront)->interf);
            while (newn != NULL)
            {
                (*front->snd_node_propagate)(front,*newfront,wave,
                                             tempintfc,tempn,newn,dt);
                tempn = next_node(tempn);
                newn = next_node(newn);
            }

            debug_front("snd_front","after snd_node prop",*newfront);
            stop_clock("snd_node_propagate");
        }

	/* Tangential Sweep for States on the Curves */

	if (front->tan_curve_propagate) 
	{
	    start_clock("tan_curve_propagate");
	    if (debugging("front"))
	    	(void) printf("Second Loop over Curves\n");
	    for (c = tempintfc->curves; c && *c; c++)
	    {
	    	tempc = *c;
	    	newc = correspond_curve(tempc);
	    	(*front->tan_curve_propagate)(front,*newfront,
	    				      tempintfc,tempc,newc,dt);
	    }
	    debug_front("tcp_front","after tan_curve_propagate:",*newfront);
	    stop_clock("tan_curve_propagate");
	}

	if (tempintfc)
	    (void) delete_interface(tempintfc);
	print_storage("after delete tempintfc","ADV_storage");

        /* 060303, delete_phys_remn_on_bdry() added */
        /* Provide robustness for untangle algorithms */
        /*   delete remnants of scalar physical   */
        /*  curves sticking to NEUMANN boundaries */
        /* Add to delete_exterior_curves()? */

        if (delete_phys_remn_on_bdry(*newfront) == NO)
        {
            (void) printf("WARNING in tangnt_advance_front2d(), "
                          "delete_phys_remn_on_bdry() detected error\n");
            debug_front("ERROR_front","after error",*newfront);
            *dt_frac = Min_time_step_modification_factor(front);
            status = MODIFY_TIME_STEP;
            goto sync_prop_stat2;
        }
        debug_front("dspr_front",
                    "after 1st delete_phys_remn_on_bdry():",*newfront);

sync_prop_stat2:  
	if (status != GOOD_STEP)
	    return return_advance_front(front,newfront,status,fname);
	return return_advance_front(front,newfront,GOOD_STEP,fname);
}		/*end tangnt_advance_front2d*/
Beispiel #12
0
Datei: FED.C Projekt: MegaGod/TW
void edit( int ch ) {
	struct viewporttype tmp;
	char key, *buff;

	take_char( ( char ) ch );
	backup_char( );
	getviewsettings( &tmp );
	setviewport( 400, 30, getmaxx( ), getmaxy( ), 1 );
	buff = ( char* ) malloc( imagesize( 0 + align, 0, X*( 2 + WIDTH_X ) + align, Y*( 2 + WIDTH_Y ) ) );
	getimage( 0 + align, 0, X*( 2 + WIDTH_X ) + align, Y*( 2 + WIDTH_Y ), buff );
	draw_char( );
	start_clock( EDIT_FONT );

	while ( ( key = get_pos( &pos_x, &pos_y, X - 1, Y - 1, 1, 1 ) ) != 3 ) {
		switch ( tolower( key ) ) {
		case 1:
			xor_dot( pos_x, pos_y );
			continue;

		case '8':
			pan_up( );
			draw_char( );
			break;

		case '2':
			pan_down( );
			draw_char( );
			break;

		case '4':
			pan_left( );
			draw_char( );
			break;

		case '6':
			pan_right( );
			draw_char( );
			break;

		case 'r':
			insert_row( pos_y );
			draw_char( );
			break;

		case 'c':
			insert_col( pos_x );
			draw_char( );
			break;

		case 'e':
			del_row( pos_y );
			draw_char( );
			break;

		case 'd':
			del_col( pos_x );
			draw_char( );
			break;

		case 'i':
			invert( );
			draw_char( );
			break;

		case 'm':
			mirror( );
			draw_char( );
			break;

		case '.':
			++draw_mode;
			switch ( draw_mode ) {
			case 0:
				break;
			case 1:
				put_dot( pos_x, pos_y );
				edit_font[pos_x][pos_y] = ~0;
				break;
			case 2:
				square( pos_x, pos_y );
				edit_font[pos_x][pos_y] = 0;
				break;
			case 3:
				draw_mode = 0;
			}
			continue;

		case 'u':
			undo( );
			draw_char( );
			goto exit;

		case '?':
			help( );
			break;

		default:
			if ( draw_mode == 1 ) {
				put_dot( pos_x, pos_y );
				edit_font[pos_x][pos_y] = ~0;
			}
			if ( draw_mode == 2 ) {
				square( pos_x, pos_y );
				edit_font[pos_x][pos_y] = 0;
			}

		}
	}
	update_char( ( char ) ch );
exit:
	putimage( 0 + align, 0, buff, COPY_PUT );
	free( buff );
	stop_clock( );
	dispblank( 50, 16, strlen( "Move mode" ), 0 );
	setviewport( tmp.left, tmp.top, tmp.right, tmp.bottom, tmp.clip );
	print_table( which_page( ch ) );
}
Beispiel #13
0
EXPORT bool make_point_comp_lists(
	INTERFACE	*intfc)
{
	int		ix, ix0, ix1;
	int		zp;
	POINT		**p;
	struct Table	*T;
	COMPONENT	icomp;
        RECT_GRID       *grid;

	if (DEBUG)
	    (void) printf("Entered make_point_comp_lists()\n");

	if ((T = table_of_interface(intfc)) == NULL) 
	{
	    (void) printf("WARNING in make_point_comp_lists(), "
	                  "table_of_interface = NULL\n");
	    return FUNCTION_FAILED;
	}

	if (no_topology_lists(intfc) == YES)
	{
	    screen("ERROR in make_point_comp_lists(), "
		   "illegal attempt to construct interface topology\n"
		   "no_topology_lists(intfc) == YES\n");
	    clean_up(ERROR);
	}

	grid = &T->rect_grid;

			/* Free old storage if necessary */

	if (T->num_of_points != NULL)
	    free(T->num_of_points);
	if (T->pts_in_zone != NULL)
	    free(T->pts_in_zone);
	if (T->compon1d != NULL)
	    free(T->compon1d);

			/* Create a Grid if Needed: */

	if (!T->fixed_grid)
	    set_topological_grid(intfc,(RECT_GRID *)NULL);


			/* Allocate new storage if necessary */

	uni_array(&T->num_of_points,grid->gmax[0],INT);
	if (T->num_of_points == NULL)
	{
	    (void) printf("WARNING in make_point_complist(), "
	                  "can't allocate T->num_of_points\n");
	    return FUNCTION_FAILED;
	}
	if (DEBUG)
	    (void) printf("T->num_of_points allocated\n");

	/* NOTE: vector returns integer values initalized to zero */
	uni_array(&T->compon1d,grid->gmax[0],sizeof(COMPONENT));
	if (T->compon1d == NULL)
	{
	    (void) printf("WARNING in make_point_complist(), "
	                  "can't allocate T->compon1d\n");
	    return FUNCTION_FAILED;
	}
	if (DEBUG)
	    (void) printf("T->compon1d allocated\n");

	for (ix = 0; ix < grid->gmax[0]; ++ix)
	    T->compon1d[ix] = NO_COMP;
	uni_array(&T->pts_in_zone,grid->gmax[0],sizeof(POINT **));
	/* NOTE: vector returns pointer values initalized to NULL */
	if (T->pts_in_zone == NULL)
	{
	    (void) printf("WARNING in make_point_complist(), "
	                  "can't allocate T->pts_in_zone\n");
	    return FUNCTION_FAILED;
	}

	start_clock("make_point_comp_lists");
	if ((intfc->modified)  && (intfc->num_points > 0))
	    sort_point_list(intfc->points,intfc->num_points);

		/* Default setting */
	ix0 = 0;
	if (intfc->num_points != 0)
	{
	    p = intfc->points;
	    icomp = negative_component(*p);
	    ix1 = -1;
	    for (p = intfc->points; p && *p; ++p)
	    {
	    	if (rect_in_which(Coords(*p),&zp,&T->rect_grid) ==
							FUNCTION_FAILED)
	    	    continue;
	    	++T->num_of_points[zp];
	    	if ((p == intfc->points) || (zp != ix1))
	    	{
	    	    T->pts_in_zone[zp] = p;
	    	}

	    	T->compon1d[zp] = ONFRONT;
	    	ix1 = zp;
	    	for (ix = ix0; ix < ix1; ++ix)
	    	    T->compon1d[ix] = icomp;
	    	icomp = positive_component(*p);
	    	ix0 = zp + 1;
	    }
	    for (ix = ix0; ix < grid->gmax[0]; ++ix)
	    	T->compon1d[ix] = icomp;
	}
	stop_clock("make_point_comp_lists");

	intfc->modified = NO;
	intfc->table->new_grid = NO;

	if (DEBUG) (void) printf("Leaving make_point_comp_lists()\n\n");
	return FUNCTION_SUCCEEDED;
}		/*end make_point_comp_lists*/
Beispiel #14
0
int main( int argc, char** argv ) 
{
  int mark_period;
  FILE* output;
  char* info_path = "/tmp/info";
  FILE* aux;
  int chunk_size = 4096; //2048;//1024;
  const char* path;
  error_t err;

  if( argc < 4 ) {
    printf("Usage: %s <mark_period> <file_to_index> <output_file> <document_info_output> <chunk_size> <document_map_output>\n", argv[0]);
    printf(" <mark_period> -- set the marking period. This program will marks every character with offset %% mark_period = 0. Marked characters store full offset information; locating is faster for smaller mark_periods, but the index will be larger. If <mark_period> is 0, no characters are marked. 20 is a reasonable value here.\n");
    printf(" <file_to_index> -- a file or directory containing the document(s) to be indexed; if it is a directory, every file in that directory will be indexed.\n");
    printf(" <output_file> -- where to store the Burrows-Wheeler Transform of the prepared text\n");
    printf(" <document_info_output> -- where to store a file containing document information (e.g. the URL of each document)\n");
    printf(" <chunk_size> -- the number of rows in the Burrows-Wheeler transform to group together and save a list of matching documents. Larger chunks mean that queries for very common terms will report faster and the index will be smaller. Smaller chunks allow the chunks to be used for less common terms. 4096 is a reasonable value here.\n");
    printf(" <document_map_output> -- where to store the list of matching documents for each <chunk_size> group of rows\n");
    exit(-1);
  }

  {
    int i = 1;
    char* name;
    sscanf(argv[i++], "%i", &mark_period);
    path = argv[i++];
    printf("Will save bwt for %s marking %i\n", path, mark_period);
    name = argv[i++];
    printf("Saving bwt to %s\n", name);
    output = fopen(name, "w+");
    if( ! output ) {
      printf("Could not open output file %s\n", name);
      die_if_err(ERR_IO_UNK);
    }
    name = argv[i++];
    printf("Saving document infos to %s\n", name);
    info_path = name;
    if( argc >= 6 ) {
      if( argc < 7 ) {
        printf("Missing <chunk_size> <doc_output_file>\n");
        exit(-1);
      }
      sscanf(argv[i++], "%i", &chunk_size);
      name = argv[i++];
      printf("Saving document map to %s chunking %i\n", name, chunk_size);
      aux = fopen(name, "w+");
      if( ! aux ) {
        printf("Could not open aux. output file %s\n", name);
        die_if_err(ERR_IO_UNK);
      }
    } else aux = NULL;
  }

  start_clock();
  // step 1: prepare the text.
  // initialize the structure
  printf("Reading and preparing text\n"); 
  start_clock();
  err = init_prepared_text(&bwt_globals.p, info_path);
  die_if_err(err);
  
  // read in any documents
  err = init_file_find(&bwt_globals.ffs, 1, &path);
  die_if_err(err);
  err = file_find(&bwt_globals.ffs, size_file, &bwt_globals);
  die_if_err(err);
  free_file_find(&bwt_globals.ffs);

  // For each file... 
  err = init_file_find(&bwt_globals.ffs, 1, &path);
  die_if_err(err);
  err = file_find(&bwt_globals.ffs, read_file, &bwt_globals);
  die_if_err(err);
  free_file_find(&bwt_globals.ffs);


  stop_clock();

  {
    int64_t num_chars, num_docs; 
    err = prepared_num_docs( &bwt_globals.p, &num_docs);
    die_if_err(err);
    err = prepared_num_chars( &bwt_globals.p, &num_chars);
    die_if_err(err);


    printf("Read %"PRIi64 " chars %" PRIi64 " documents \n",
           num_chars, num_docs);

    print_timings("preparing bytes", num_chars );
  }


  printf("Creating output\n");
  err = save_prepared_bwt(&bwt_globals.p, mark_period,
                          output, chunk_size, aux, 1);
  die_if_err(err);
  
  free_prepared_text(&bwt_globals.p);

  return 0;
}
Beispiel #15
0
int main(int argc, char** argv){
	float tr[6];

	const float ZAP=32;
	const uint64_t TSIZE=18;
	const uint64_t zapE=64;
	fftwf_init_threads();
	fftwf_plan_with_nthreads(omp_get_max_threads());

	logmsg("Open file '%s'",argv[1]);
	FILE* f = fopen(argv[1],"r");

	int hdr_bytes = read_header(f);
	const uint64_t nskip = hdr_bytes;
	const uint64_t nchan = nchans;
	logmsg("Nchan=%"PRIu64", tsamp=%f",nchan,tsamp);
	mjk_rand_t *random = mjk_rand_init(12345);

	rewind(f);
	FILE* of = fopen("clean.fil","w");
	uint8_t hdr[nskip];
	fread(hdr,1,nskip,f);
	fwrite(hdr,1,nskip,of);
	const uint64_t nsamp_per_block=round(pow(2,TSIZE));

	logmsg("Tblock = %f",nsamp_per_block*tsamp);

	mjk_clock_t *t_all = init_clock();
	start_clock(t_all);

	mjk_clock_t *t_read = init_clock();
	mjk_clock_t *t_trns= init_clock();
	mjk_clock_t *t_rms = init_clock();
	mjk_clock_t *t_fft = init_clock();
	mjk_clock_t *t_spec = init_clock();

	const uint64_t bytes_per_block = nchan*nsamp_per_block;

	uint8_t *buffer = calloc(bytes_per_block,1);
	float **data = malloc_2df(nchan,nsamp_per_block);
	float **clean = malloc_2df(nchan,nsamp_per_block);
	float *bpass = calloc(nchan,sizeof(float));
	float  *ch_var=NULL;
	float  *ch_mean=NULL;
	float  *ch_fft_n=NULL;
	float  *ch_fft_p=NULL;


	logmsg("Planning FFT - this will take a long time the first time it is run!");
	start_clock(t_fft);
	FILE * wisfile;
	if(wisfile=fopen("wisdom.txt","r")){
		fftwf_import_wisdom_from_file(wisfile);
		fclose(wisfile);
	}
	const int fftX=nsamp_per_block;
	const int fftY=nchan;
	const int fftXo=nsamp_per_block/2+1;

	float *X = fftwf_malloc(sizeof(float)*fftX);

	for (uint64_t i = 0; i < nsamp_per_block ; i++){
		X[i]=i;
	}
	float *tseries = fftwf_malloc(sizeof(float)*fftX);
	float complex *fseries = fftwf_malloc(sizeof(float complex)*fftXo);
	float *pseries = fftwf_malloc(sizeof(float)*fftXo);
	uint8_t *mask = malloc(sizeof(uint8_t)*fftXo);
	fftwf_plan fft_1d = fftwf_plan_dft_r2c_1d(fftX,tseries,fseries,FFTW_MEASURE|FFTW_DESTROY_INPUT);

	complex float * fftd = fftwf_malloc(sizeof(complex float)*(fftXo*fftY));
	fftwf_plan fft_plan = fftwf_plan_many_dft_r2c(
			1,&fftX,fftY,
			data[0] ,&fftX,1,fftX,
			fftd    ,&fftXo,1,fftXo,
			FFTW_MEASURE|FFTW_PRESERVE_INPUT);
	logmsg("Planning iFFT - this will take a long time the first time it is run!");
	fftwf_plan ifft_plan = fftwf_plan_many_dft_c2r(
			1,&fftX,fftY,
			fftd ,&fftXo,1,fftXo,
			clean[0] ,&fftX,1,fftX,
			FFTW_MEASURE|FFTW_PRESERVE_INPUT);

	if(!fft_plan){
		logmsg("Error - could not do FFT plan");
		exit(2);
	}

	wisfile=fopen("wisdom.txt","w");
	fftwf_export_wisdom_to_file(wisfile);
	fclose(wisfile);
	stop_clock(t_fft);
	logmsg("T(planFFT)= %.2lfs",read_clock(t_fft));
	reset_clock(t_fft);



	float min_var=1e9;
	float max_var=0;

	float min_fft_n=1e9;
	float max_fft_n=0;


	float min_fft_p=1e9;
	float max_fft_p=0;

	float min_mean=1e9;
	float max_mean=0;
	uint64_t nblocks=0;
	uint64_t totread=0;
	while(!feof(f)){
		nblocks++;
		ch_var = realloc(ch_var,nchan*nblocks*sizeof(float));
		ch_mean = realloc(ch_mean,nchan*nblocks*sizeof(float));
		ch_fft_n = realloc(ch_fft_n,nchan*nblocks*sizeof(float));
		ch_fft_p = realloc(ch_fft_p,nchan*nblocks*sizeof(float));
		start_clock(t_read);
		uint64_t read = fread(buffer,1,bytes_per_block,f);
		stop_clock(t_read);
		if (read!=bytes_per_block){
			nblocks--;
			break;
		}
		totread+=read;
		logmsg("read=%"PRIu64" bytes. T=%fs",read,totread*tsamp/(float)nchan);
		uint64_t offset = (nblocks-1)*nchan;
		start_clock(t_trns);
		// transpose with small blocks in order to increase cache efficiency.
#define BLK 8
#pragma omp parallel for schedule(static,2) shared(buffer,data)
		for (uint64_t j = 0; j < nchan ; j+=BLK){
			for (uint64_t i = 0; i < nsamp_per_block ; i++){
				for (uint64_t k = 0; k < BLK ; k++){
					data[j+k][i] = buffer[i*nchan+j+k];
				}
			}
		}

#pragma omp parallel for shared(data)
		for (uint64_t j = 0; j < nchan ; j++){
			if(j<zapE || (nchan-j) < zapE){ 
				for (uint64_t i = 0; i < nsamp_per_block ; i++){
					data[j][i]=ZAP;
				}
			}
		}

		if(nblocks==1){
#pragma omp parallel for shared(data,bpass)
			for (uint64_t j = 0; j < nchan ; j++){
				for (uint64_t i = 0; i < nsamp_per_block ; i++){
					bpass[j]+=data[j][i];
				}
				bpass[j]/=(float)nsamp_per_block;
				bpass[j]-=ZAP;
			}
		}
#pragma omp parallel for shared(data,bpass)
		for (uint64_t j = 0; j < nchan ; j++){
			for (uint64_t i = 0; i < nsamp_per_block ; i++){
				data[j][i]-=bpass[j];
			}
		}




		stop_clock(t_trns);

		start_clock(t_rms);
#pragma omp parallel for shared(data,ch_mean,ch_var)
		for (uint64_t j = 0; j < nchan ; j++){
			float mean=0;
			for (uint64_t i = 0; i < nsamp_per_block ; i++){
				mean+=data[j][i];
			}
			mean/=(float)nsamp_per_block;
			if(mean > ZAP+5 || mean < ZAP-5){
				logmsg("ZAP ch=%"PRIu64,j);
				for (uint64_t i = 0; i < nsamp_per_block ; i++){
					data[j][i]=ZAP;
				}
			}

			float ss=0;
			float x=0;
			for (uint64_t i = 0; i < nsamp_per_block ; i++){
				x = data[j][i]-mean;
				ss+=x*x;
			}
			float var=ss/(float)nsamp_per_block;
			if (var > 0){
				for (uint64_t i = 0; i < nsamp_per_block ; i++){
					float v = (data[j][i]-mean)/sqrt(var);
					if(v > 3 || v < -3){
						data[j][i]=mjk_rand_gauss(random)*sqrt(var)+mean;
					}
				}
			}

			ch_var[offset+j] = var;
			ch_mean[offset+j] = mean;

		}
		stop_clock(t_rms);

		for (uint64_t i = 0; i < nsamp_per_block ; i++){
			tseries[i]=0;
		}

		float tmean=0;
		float tvar=0;
		float max=0;
		float min=1e99;
		//#pragma omp parallel for shared(data,tseries)
		// NOT THREAD SAFE
		for (uint64_t j = 0; j < nchan ; j++){
			tmean+=ch_mean[offset+j];
			tvar+=ch_var[offset+j];
			for (uint64_t i = 0; i < nsamp_per_block ; i++){
				tseries[i]+=data[j][i];
				if(data[j][i]>max)max=data[j][i];
				if(data[j][i]<min)min=data[j][i];
			}
		}
		float ss=0;
		float mm=0;
		for (uint64_t i = 0; i < nsamp_per_block ; i++){
			float x=tseries[i]-tmean;
			mm+=tseries[i];
			ss+=x*x;
		}
		float rvar=ss/(float)nsamp_per_block;
		logmsg("var=%g tvar=%g",ss/(float)nsamp_per_block,tvar);
		logmsg("mean=%g tmean=%g",mm/(float)nsamp_per_block,tmean);
		cpgopen("3/xs");
		cpgsvp(0.1,0.9,0.1,0.9);
		cpgswin(0,fftX,tmean-sqrt(tvar)*30,tmean+sqrt(tvar)*30);
		cpgbox("ABN",0,0,"ABN",0,0);
		cpgline(fftX,X,tseries);
		cpgsci(2);
		cpgclos();
		tr[0] = 0.0 ;
		tr[1] = 1;
		tr[2] = 0;
		tr[3] = 0.5;
		tr[4] = 0;
		tr[5] = 1;

		logmsg("max=%g min=%g",max,min);

		cpgopen("4/xs");
		cpgsvp(0.1,0.9,0.1,0.9);
		cpgswin(0,nsamp_per_block,0,nchan);
		cpgbox("ABN",0,0,"ABN",0,0);
		cpggray(*data,nsamp_per_block,nchan,1,nsamp_per_block,1,nchan,tmean/(float)nchan+sqrt(rvar/(float)nchan),tmean/(float)nchan-sqrt(rvar/(float)nchan),tr);
		cpgclos();




		start_clock(t_fft);
		fftwf_execute(fft_1d);
		fftwf_execute(fft_plan);
		stop_clock(t_fft);

		{
			float T = sqrt(fftXo*tvar)*12;
			logmsg("Zap T=%.2e",T);

			float fx[fftXo];
			float fT[fftXo];
#pragma omp parallel for shared(fseries,pseries,mask)
			for (uint64_t i = 0; i < fftXo ; i++){
				mask[i]=1;
			}
#pragma omp parallel for shared(fseries,pseries,mask)
			for (uint64_t i = 0; i < fftXo ; i++){
				pseries[i]=camp(fseries[i]);
				fx[i]=i;
				float TT = T;
				if (i>512)TT=T/2.0;
				if(i>32){
					fT[i]=TT;
					if (pseries[i] > TT) {
						mask[i]=0;
					}
				} else fT[i]=0;
			}

			uint64_t nmask=0;
			for (uint64_t i = 0; i < fftXo ; i++){
				if (mask[i]==0){
					nmask++;
				}
			}
			logmsg("masked=%d (%.2f%%)",nmask,100*nmask/(float)fftXo);
			cpgopen("1/xs");
			cpgsvp(0.1,0.9,0.1,0.9);
			cpgswin(0,fftXo,0,T*10);
			cpgbox("ABN",0,0,"ABN",0,0);
			cpgline(fftXo,fx,pseries);
			cpgsci(2);
			cpgline(fftXo,fx,fT);
			cpgclos();

		}


		//		exit(1);

		start_clock(t_spec);

		//FILE* ff=fopen("plot","w");
#pragma omp parallel for shared(fftd,ch_mean,ch_fft_n,ch_fft_p)
		for (uint64_t j = 0; j < nchan ; j++){
			float var = ch_var[offset+j];
			float m=sqrt(var*fftXo/2.0);
			float T = sqrt(var*fftXo)*3;
			uint64_t n=0;
			float p=0;
			float complex *fftch = fftd + fftXo*j;
			for(uint64_t i = 1; i < fftXo; i++){
				if (camp(fftch[i]) > T) {
					n++;
					p+=camp(fftch[i]);
				}
				//	 if(j==512)fprintf(ff,"%f ",camp(fftch[i]));
				if(mask[i]==0){
					fftch[i]=m*(mjk_rand_gauss(random) + I*mjk_rand_gauss(random)); 
				}
				//	 if(j==512)fprintf(ff,"%f\n",camp(fftch[i]));
			}
			ch_fft_n[offset+j]=n;
			ch_fft_p[offset+j]=p;
		}
		// fclose(ff);

		logmsg("iFFT");
		fftwf_execute(ifft_plan);

#pragma omp parallel for schedule(static,2) shared(buffer,clean)
		for (uint64_t j = 0; j < nchan ; j+=BLK){
			for (uint64_t i = 0; i < nsamp_per_block ; i++){
				for (uint64_t k = 0; k < BLK ; k++){
					clean[j+k][i]/=(float)fftX;
					buffer[i*nchan+j+k] = round(clean[j+k][i]);
				}
			}

			if(j==512){
				cpgopen("2/xs");
				cpgsvp(0.1,0.9,0.1,0.9);
				cpgswin(0,fftX,ch_mean[j]-sqrt(ch_var[j])*10,ch_mean[j]+sqrt(ch_var[j])*10);
				cpgbox("ABN",0,0,"ABN",0,0);
				cpgline(fftX,X,data[j]);
				cpgsci(2);
				cpgline(fftX,X,clean[j]);
				cpgclos();

			}

		}
		fwrite(buffer,1,bytes_per_block,of);


		for (uint64_t i = 0; i < nsamp_per_block ; i++){
			tseries[i]=0;
		}

		tmean=0;
		tvar=0;
		max=0;
		min=1e99;
		//#pragma omp parallel for shared(clean,tseries)
		// NOT THREAD SAFE
		for (uint64_t j = 0; j < nchan ; j++){
			tmean+=ch_mean[offset+j];
			tvar+=ch_var[offset+j];
			for (uint64_t i = 0; i < nsamp_per_block ; i++){
				tseries[i]+=clean[j][i];
				if(clean[j][i]>max)max=clean[j][i];
				if(clean[j][i]<min)min=clean[j][i];
			}
		}
		ss=0;
		mm=0;
		for (uint64_t i = 0; i < nsamp_per_block ; i++){
			float x=tseries[i]-tmean;
			mm+=tseries[i];
			ss+=x*x;
		}
		rvar=ss/(float)nsamp_per_block;
		logmsg("var=%g tvar=%g",ss/(float)nsamp_per_block,tvar);
		logmsg("mean=%g tmean=%g",mm/(float)nsamp_per_block,tmean);
		cpgopen("5/xs");
		cpgsvp(0.1,0.9,0.1,0.9);
		cpgswin(0,fftX,tmean-sqrt(tvar)*30,tmean+sqrt(tvar)*30);
		cpgbox("ABN",0,0,"ABN",0,0);
		cpgline(fftX,X,tseries);
		cpgsci(2);
		cpgclos();
		tr[0] = 0.0 ;
		tr[1] = 1;
		tr[2] = 0;
		tr[3] = 0.5;
		tr[4] = 0;
		tr[5] = 1;

		logmsg("max=%g min=%g",max,min);

		cpgopen("6/xs");
		cpgsvp(0.1,0.9,0.1,0.9);
		cpgswin(0,nsamp_per_block,0,nchan);
		cpgbox("ABN",0,0,"ABN",0,0);
		cpggray(*clean,nsamp_per_block,nchan,1,nsamp_per_block,1,nchan,tmean/(float)nchan+sqrt(rvar/(float)nchan),tmean/(float)nchan-sqrt(rvar/(float)nchan),tr);
		cpgclos();




		stop_clock(t_spec);
		for (uint64_t j = 0; j < nchan ; j++){
			float mean=ch_mean[offset+j];
			if (mean > max_mean)max_mean=mean;
			if (mean < min_mean)min_mean=mean;

			float var=ch_var[offset+j];
			if (var > max_var)max_var=var;
			if (var < min_var)min_var=var;
			float fft_n=ch_fft_n[offset+j];
			if (fft_n > max_fft_n)max_fft_n=fft_n;
			if (fft_n < min_fft_n)min_fft_n=fft_n;
			float fft_p=ch_fft_p[offset+j];
			if (fft_p > max_fft_p)max_fft_p=fft_p;
			if (fft_p < min_fft_p)min_fft_p=fft_p;

		}
	}
	stop_clock(t_all);

	fclose(of);

	logmsg("T(all)  = %.2lfs",read_clock(t_all));
	logmsg("T(read) = %.2lfs",read_clock(t_read));
	logmsg("T(trans)= %.2lfs",read_clock(t_trns));
	logmsg("T(fft)  = %.2lfs",read_clock(t_fft));
	logmsg("T(fan)  = %.2lfs",read_clock(t_spec));
	logmsg("T(rms)  = %.2lfs",read_clock(t_rms));
	logmsg("T(rest) = %.2lfs",read_clock(t_all)-read_clock(t_read)-read_clock(t_trns)-read_clock(t_rms)-read_clock(t_fft)-read_clock(t_spec));


	tr[0] = -tsamp*nsamp_per_block*0.5;
	tr[2] = tsamp*nsamp_per_block;
	tr[1] = 0;
	tr[3] = 0.5;
	tr[5] = 0;
	tr[4] = 1;




	cpgopen("1/xs");
	cpgsvp(0.1,0.9,0.1,0.9);
	cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan);
	cpgbox("ABN",600,10,"ABN",100,1);
	cpggray(ch_mean,nchan,nblocks,1,nchan,1,nblocks,max_mean,min_mean,tr);
	cpgclos();

	cpgopen("2/xs");
	cpgsvp(0.1,0.9,0.1,0.9);
	cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan);
	cpgbox("ABN",600,10,"ABN",100,1);
	cpggray(ch_var,nchan,nblocks,1,nchan,1,nblocks,max_var,min_var,tr);
	cpgclos();

	cpgopen("3/xs");
	cpgsvp(0.1,0.9,0.1,0.9);
	cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan);
	cpgbox("ABN",600,10,"ABN",100,1);
	cpggray(ch_fft_n,nchan,nblocks,1,nchan,1,nblocks,max_fft_n,min_fft_n,tr);
	cpgclos();

	cpgopen("4/xs");
	cpgsvp(0.1,0.9,0.1,0.9);
	cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan);
	cpgbox("ABN",600,10,"ABN",100,1);
	cpggray(ch_fft_p,nchan,nblocks,1,nchan,1,nblocks,max_fft_p,min_fft_p,tr);
	cpgclos();



	cpgopen("mean.ps/vcps");
	cpgsvp(0.1,0.9,0.1,0.9);
	cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan);
	cpgbox("ABN",600,10,"ABN",100,1);
	cpggray(ch_mean,nchan,nblocks,1,nchan,1,nblocks,max_mean,min_mean,tr);
	cpgclos();

	cpgopen("var.ps/vcps");
	cpgsvp(0.1,0.9,0.1,0.9);
	cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan);
	cpgbox("ABN",600,10,"ABN",100,1);
	cpggray(ch_var,nchan,nblocks,1,nchan,1,nblocks,max_var,min_var,tr);
	cpgclos();


	cpgopen("fft_n.ps/vcps");
	cpgsvp(0.1,0.9,0.1,0.9);
	cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan);
	cpgbox("ABN",600,10,"ABN",100,1);
	cpggray(ch_fft_n,nchan,nblocks,1,nchan,1,nblocks,max_fft_n,min_fft_n,tr);
	cpgclos();

	cpgopen("fft_p.ps/vcps");
	cpgsvp(0.1,0.9,0.1,0.9);
	cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan);
	cpgbox("ABN",600,10,"ABN",100,1);
	cpggray(ch_fft_p,nchan,nblocks,1,nchan,1,nblocks,max_fft_p,min_fft_p,tr);
	cpgclos();



	fclose(f);
	free(buffer);
	free_2df(data);

	return 0;

}
Beispiel #16
0
void update_links( void )
{
  char_data*            ch;
  link_data*          link;
  text_data*       receive;
  fd_set          read_set;
  fd_set         write_set;
  fd_set          exec_set;
  struct timeval     start;  
  struct timeval   timeout;  

  gettimeofday( &start, NULL );

  timeout.tv_sec  = 1;
  timeout.tv_usec = 0;

  FD_ZERO( &read_set );
  FD_ZERO( &write_set );
  FD_ZERO( &exec_set );

  FD_SET( socket_one, &read_set );
  FD_SET( socket_two, &read_set );

  for( link = link_list; link != NULL; link = link->next ) {
    FD_SET( link->channel, &read_set  );
    FD_SET( link->channel, &write_set );
    FD_SET( link->channel, &exec_set );
    }

  if( (int) select( FD_SETSIZE, &read_set, &write_set, &exec_set,
    &timeout ) < 0 ) 
    panic( "Update links: select" );

  if( FD_ISSET( socket_one, &read_set ) )
    open_link( socket_one );

  if( FD_ISSET( socket_two, &read_set ) )
    open_link( socket_two );

  for( link = link_list; link != NULL; link = link_next ) {
    link_next = link->next;
  
    if( FD_ISSET( link->channel, &exec_set ) ) {
      write( link->player );
      close_socket( link );
      continue;
      }
  
    if( FD_ISSET( link->channel, &read_set ) ) {
      link->idle = 0;
      if( link->player != NULL )
        link->player->timer = current_time;
      if( !read_link( link ) ) {
        write( link->player );
        close_socket( link );
        continue;
        }
      }

    if( link->idle++ > 10000 && link->connected != CON_PLAYING ) {
      send( link, "\n\r\n\r-- CONNECTION TIMEOUT --\n\r" );
      close_socket( link, TRUE );
      }
    }

  pulse_time[ TIME_READ_INPUT ] = stop_clock( start );  
  gettimeofday( &start, NULL );

  for( link = link_list; link != NULL; link = link_next ) {
    link_next = link->next;
    if( link->command = ( ( receive = link->receive ) != NULL ) ) {
      ampersand( receive );
      link->receive  = receive->next;
      link->idle     = 0; 
      if( link->connected == CON_PLAYING ) {
        stop_idling( ch = link->character );
        interpret( link->character, receive->message.text );
        }  
      else
        nanny( link, receive->message.text );
      delete receive;
      }
    }

  pulse_time[ TIME_COMMANDS ] = stop_clock( start );  
  gettimeofday( &start, NULL );

  for( link = link_list; link != NULL; link = link_next ) {
    link_next = link->next;
    if( link->idle%25 == 0 && FD_ISSET( link->channel, &write_set )
      && !process_output( link ) ) {
      write( link->player );
      close_socket( link );
      }
    }  
  
  pulse_time[ TIME_WRITE_OUTPUT ] = stop_clock( start );  

  return;
}
Beispiel #17
0
EXPORT int normal_advance_front2d(
	float    dt,
	float    *dt_frac,
	Front    *front,
	Front    **newfront,
	POINTER  wave)
{
	CURVE      *oldc,*newc;
	CURVE	   **c;
	NODE 	   *oldn,*newn;
	RPROBLEM   *rp,*rp1;
	int        status, node_stat;
        NODE_FLAG  flag;  
	const char *fname = "normal_advance_front2d()";

	debug_print("front","Entered %s(step %d time %g dt %g)\n",fname,
	        	        front->step,front->time,dt);
	debug_front("old_front","into advance front",front);

	*newfront = copy_front(front);
	Interface_redistributed(*newfront) = NO;

        if(front->interf->nodes == NULL)
        {
            bool       sav_copy;
            INTERFACE  *sav_intfc;  
            sav_intfc = current_interface();
            sav_copy = copy_intfc_states();
            set_size_of_intfc_state(size_of_state(front->interf));
            set_copy_intfc_states(YES);
            (*newfront)->interf = copy_interface(front->interf);
            set_current_interface(sav_intfc);
            set_copy_intfc_states(sav_copy);
            return return_advance_front(front,newfront,GOOD_STEP,fname);  
        }

	rp = NULL;

        set_to_next_node_only(flag);  

	set_node_doubly_linked_list(front->interf);

	        /* Initialize Newfront */

	start_clock("init_new_front");
	capture_waves(front);
	print_storage("before init_new_front","ADV_storage");
	        /* TODO: Remove this option!!!!! */
	if (front->init_topology_of_new_interface)
	    status = (*front->init_topology_of_new_interface)(front,*newfront);
	else 
	{
	    set_size_of_intfc_state(size_of_state(front->interf));
	    set_copy_intfc_states(NO);
	    set_add_to_correspond_list(YES);
            /* 
            If USE_OVERTURE, can not syncronize_time_step at here 
	    (*newfront)->interf = pp_copy_interface(front->interf);
            */ 
	    (*newfront)->interf = copy_interface(front->interf);
	    reset_hs_flags_on_intfc((*newfront)->interf);
	    status = ((*newfront)->interf != NULL) ? GOOD_STEP : ERROR_IN_STEP;
	    set_copy_intfc_states(YES);
	}
        if (status != GOOD_STEP)
        {
            (void) printf("ERROR in normal_advance_front2d(), "
                          "unable to copy interface\n");
            print_storage("after init_new_front","ADV_storage");
            clean_up(ERROR);
        }
	print_storage("after init_new_front","ADV_storage");
	stop_clock("init_new_front");

	        /* Set Default Propagation Limits */

	set_propagation_limits(front,*newfront);

	        /* Propagate the Curves */

	if (front->curve_propagate != NULL) 
	{
	    start_clock("curve_propagate");
	    if (debugging("front"))
	    	(void) printf("Loop over Curves\n");
	    for (c = front->interf->curves; c && *c; c++)
	    {
	        oldc = *c;
	        if (((newc = correspond_curve(oldc)) != NULL) &&
	    	     (correspond_curve(newc) != NULL))
	        {
	    	    if (debugging("propagate"))
	                (void) printf("\t\tpropagating curve %lu\n",
		                      curve_number(oldc));
		    curve_propagate(front,wave,oldc,newc,dt);
		}
	    }
	    debug_front("cp_front","after curve prop",*newfront);
	    stop_clock("curve_propagate");
	}

		/* Propagate the Nodes */

	if (debugging("front"))
	{
	    print_correspond_hyper_surf_list(front->interf);
	    print_correspond_hyper_surf_list((*newfront)->interf);
	}
	if (front->node_propagate != NULL) 
	{
	    start_clock("node_propagate");
	    set_corresponds_for_node_prop(front->interf,(*newfront)->interf);
	    oldn = first_node(front->interf);
	    while (oldn != NULL) 
	    {
	        newn = correspond_node(oldn);
	        if (debugging("crx_status"))
	            print_linked_node_list((*newfront)->interf);
                if(DEBUG)
                {
                    /* 
                    printf("IN normal_advance_front2d\n");  
                    printf("node propagate\n");
                    print_node(oldn);
                    print_node(newn); 
                    printf("oldnode is virtual fixed = %s\n",
                       is_virtual_fixed_node(oldn) == YES ?
                       "YES" : "NO"); 
                    printf("newnode is virtual fixed = %s\n",
                       is_virtual_fixed_node(newn) == YES ?
                       "YES" : "NO"); 
                    printf("End of print new and old nodes\n");  
                    */  
                } 
	        status = (newn != NULL) ?
	            (*front->node_propagate)(front,wave,oldn,newn,&rp,
	        			     dt,dt_frac,flag,NULL) : GOOD_NODE;
	        if (is_bad_status(status) &&
	          (point_in_buffer(Coords(oldn->posn),front->rect_grid) == YES))
	        {
	            (void) printf("WARNING in normal_advance_front2d(), "
	                          "node_propagation returns ");
                    print_node_status("WARNING in normal_advance_front2d(), "
                                      "node_propagation returns ",status,"\n"); 
                    /* 
	            print_node_status(status);
                    */  
	            (void) printf("Problem occurs in buffer zone - ignoring\n");
	            if (set_node_states_and_continue(oldn,newn,front))
	                status = GOOD_NODE;
	        }

	        switch (status) 
	        {
	        case GOOD_NODE:
	            oldn = adv_node_loop_after_good_prop(oldn,newn,&rp);
	            break;
	        case PSEUDOCROSS_NODE_NODE:
	            debug_print("PSEUDOCROSS","PSEUDOCROSS case\n");
	            oldn = reorder_node_loop(oldn,newn);
	            break;
	        case CROSS_NODE_NODE:
	        case BIFURCATION_NODE:
	            debug_print("CROSS","CROSS case\n");
	            oldn = next_node(oldn);
	            break;
	        case CROSS_PAST_CURVE_NODE:
	            (void) printf("WARNING in normal_advance_front2d(), ");
	            (void) printf("node_propagate failed, ");
                    print_node_status("WARNING in normal_advance_front2d(), "
                                      "node_propagate failed with status ",
                                      status,"\n");
	            print_node(oldn);
	            if (debugging("CROSS_PAST"))
	            {
	                (void) printf("Cross past curve case\n"
	                              "dt_frac = %g\n",*dt_frac);
	                (void) printf("Reducing time step\n");
	            }
	            *dt_frac *= TIME_STEP_REDUCTION_FACTOR(front->interf);
	            free_rp_list(&rp);
	            status = MODIFY_TIME_STEP;
	            goto sync_prop_stat1;
	        case MODIFY_TIME_STEP_NODE:
	            (void) printf("WARNING in normal_advance_front2d(), "
	                          "node_propagate returns "
	                          "MODIFY_TIME_STEP_NODE\n");
	            free_rp_list(&rp);
	            status = MODIFY_TIME_STEP;
	            goto sync_prop_stat1;
	        case REPEAT_TIME_STEP_NODE:
	            (void) printf("WARNING in normal_advance_front2d(), "
	                          "node_propagate returns "
	                          "REPEAT_TIME_STEP_NODE\n");
	            free_rp_list(&rp);
	            status = REPEAT_TIME_STEP;
	            goto sync_prop_stat1;
	        case NO_CROSS_NODE:
	            (void) printf("WARNING in normal_advance_front2d(), ");
	            (void) printf("node_propagate failed, ");
                    print_node_status("WARNING in normal_advance_front2d(), "
                                      "node_propagate failed with status ",
                                      status,"\n"); 
	            print_node(oldn);
	            if (debugging("NO_CROSS"))
	            {
	                (void) printf("No cross case\n");
	                (void) printf("dt_frac = %g\n",*dt_frac);
	                (void) printf("Reducing time step\n");
	            }
	            *dt_frac *= TIME_STEP_REDUCTION_FACTOR(front->interf);
	            free_rp_list(&rp);
	            status = MODIFY_TIME_STEP;
	            goto sync_prop_stat1;
	        case ERROR_NODE:
	        default:
	            (void) printf("WARNING in normal_advance_front2d(), ");
	            (void) printf("node_propagate failed, ");
                    print_node_status("WARNING in normal_advance_front2d(), "
                                      "node_propagate failed with status ",
                                      status,"\n");
	            print_node(oldn);
	            if (debugging("ERROR_NODE"))
	            {
	                (void) printf("Old interface:\n");
	                print_interface(front->interf);
	                print_correspond_hyper_surf_list(front->interf);
	                (void) printf("New interface:\n");
	                print_interface((*newfront)->interf);
	                print_correspond_hyper_surf_list((*newfront)->interf);
	            }
	            *dt_frac = Min_time_step_modification_factor(front);
	            free_rp_list(&rp);
	            status = MODIFY_TIME_STEP;
	            goto sync_prop_stat1;
	        }
	    } /* end of while (oldn != NULL) */

	    set_correspond_hyper_surf_bdrys_to_NULL(front->interf);
	    set_correspond_hyper_surf_bdrys_to_NULL((*newfront)->interf);
	    if (rp && (front->twodrproblem != NULL)) 
	    {
	        for (rp1 = rp; rp1; rp1 = rp1->prev) 
	        {
	            debug_front("2drp_front",
	                "new between node loop and rp loop",*newfront);
	                    
	            status = (*front->twodrproblem)(front,*newfront,wave,&rp1);

	            /* At this point, rp is nothing more than a valid element
	             * of the list which provides a starting point
	             * for deleting the list.  If we delete an element of
	             * the list in front->twodrproblem (presumably due to
	             * merging two RPROBLEM's), then rp may point to freed
	             * storage and will need to be updated.  rp1 should still
	             * be a valid element of the list.
	             */
	            rp = rp1;

                    if (status != GOOD_STEP)
                    {
                        print_time_step_status("WARNING in advance_front2d(), "
                                               "rp failed with status = ",
                                               status,"\n");
                        switch (status)
                        {
                        case GOOD_STEP:
                            break;

                        case REPEAT_TIME_STEP:
                            break;
                        case MODIFY_TIME_STEP:
                            status = rp_modify_time_step(rp1,front,status);
                            if (status == MODIFY_TIME_STEP)
                            {
                                *dt_frac = rp1->dt_frac;
                                if (debugging("2drp"))
                                {
                                    print_rproblem(rp1);
                                    (void) printf("dt_frac %g\n",*dt_frac);
                                    (void) printf("Reducing time step\n");
                                }
                                *dt_frac = limit_dt_frac(*dt_frac,front);
                            }
                            break;

                        case ERROR_IN_STEP:
                        default:
                            print_rproblem(rp1);
                            /* Try reducing the time step */
                            status = rp_modify_time_step(rp1,front,status);
                            if (status == MODIFY_TIME_STEP)
                                *dt_frac *=
                                    TIME_STEP_REDUCTION_FACTOR(front->interf);
                            break;
                        }
                    }
                    if (status != GOOD_STEP)
                        break;
	        }
	        free_rp_list(&rp);
	        debug_front("2drp_front","after 2drp loop",*newfront);
	    }
	    else if (rp) 
	    {
	        for (rp1 = rp; rp1; rp1 = rp1->prev) 
	        {
	            print_rproblem(rp1);
	        }
	        free_rp_list(&rp);
	        (void) printf("WARNING in normal_advance_front2d(), ");
	        (void) printf("CROSS code needed\n");
	        status = ERROR_IN_STEP;
	    }
	}
        /* 061003 closed, since the correspondence is reset. 
         * The second node prop. is done in tangential step now. 
        node_stat = second_node_propagate2d(dt,dt_frac,front,newfront,wave);
        if(GOOD_STEP != node_stat) 
        {
            (void) printf("WARNING in normal_advance_front2d(), "
                      "second node_propagation returns stat= %d", node_stat);
            clean_up(ERROR);  
        }  
        */
sync_prop_stat1:
	return return_advance_front(front,newfront,GOOD_STEP,fname);
}		/*end normal_advance_front2d*/
Beispiel #18
0
LOCAL int advance_front2d(
	double    dt,
	double    *dt_frac,
	Front    *front,
	Front    **newfront,
	POINTER  wave)
{
	CURVE      *oldc,*tempc,*newc;
	CURVE	   **c;
	INTERFACE  *tempintfc;
	NODE 	   *oldn,*tempn,*newn;
	NODE_FLAG  flag;
	RPROBLEM   *rp;
	RPROBLEM   *rp1;
	boolean	   scatter_normally_propagated_front = YES;
	boolean	   scatter_tangentially_propagated_front = YES;
	boolean	   stat;
	boolean       do_redist;
	int        status;
	long       intfc_modified;
	long       redo_advance_front;
	static const char *fname = "advance_front2d()";
	int	   debug_flag = NO;

	debug_print("front","Entered %s(step %d time %g dt %g)\n",fname,
	        	        front->step,front->time,dt);
	debug_front("old_front","into advance front",front);

	*newfront = copy_front(front);
	Interface_redistributed(*newfront) = NO;
	do_redist = (front->num_mts == 0) ? YES : NO;

begin_advance_front2d:
	redo_advance_front = 0;
	tempintfc = NULL;
	rp = NULL;
	set_to_next_node_only(flag);

	set_node_doubly_linked_list(front->interf);

	        /* Initialize Newfront */

	start_clock("init_new_front");
	capture_waves(front);
	print_storage("before init_new_front","ADV_storage");
	        /* TODO: Remove this option!!!!! */
	if (front->init_topology_of_new_interface)
	    status = (*front->init_topology_of_new_interface)(front,*newfront);
	else 
	{
	    set_size_of_intfc_state(size_of_state(front->interf));
	    set_copy_intfc_states(NO);
	    set_add_to_correspond_list(YES);
	    (*newfront)->interf = pp_copy_interface(front->interf);
	    reset_hs_flags_on_intfc((*newfront)->interf);
	    status = ((*newfront)->interf != NULL) ? GOOD_STEP : ERROR_IN_STEP;
	    set_copy_intfc_states(YES);
	}
	if (front->pp_grid)
	    status = syncronize_time_step_status(status,front->pp_grid);
	if (status != GOOD_STEP) 
	{
	    (void) printf("WARNING in advance_front2d(), "
	                  "unable to copy interface\n");
	    status = ERROR_IN_STEP;
	    stop_clock("init_new_front");
	    return return_advance_front(front,newfront,status,fname);
	}
	print_storage("after init_new_front","ADV_storage");
	stop_clock("init_new_front");

	        /* Set Default Propagation Limits */

	set_propagation_limits(front,*newfront);

	        /* Propagate the Curves */

	if (front->intfc_propagate != NULL)
	{
	    start_clock("intfc_propagate");
	    intfc_propagate(front,wave,front->interf,(*newfront)->interf,dt);
	    debug_front("cp_front","after intfc prop",*newfront);
	    stop_clock("curve_propagate");
	}
	else if (front->curve_propagate != NULL) 
	{
	    start_clock("curve_propagate");
	    if (debugging("front"))
	    	(void) printf("Loop over Curves\n");
	    for (c = front->interf->curves; c && *c; ++c)
	    {
	        oldc = *c;
	        if (((newc = correspond_curve(oldc)) != NULL) &&
	    	     (correspond_curve(newc) != NULL))
	        {
	    	    if (debugging("propagate"))
	                (void) printf("\t\tpropagating curve %llu\n",
		                      (long long unsigned int)curve_number(oldc));
		    curve_propagate(front,wave,oldc,newc,dt);
		    /*f_curve_propagate2d */
		}
	    }
	    debug_front("cp_front","after curve prop",*newfront);
	    stop_clock("curve_propagate");
	}

		/* Propagate the Nodes */

	if (debugging("front"))
	{
	    print_correspond_hyper_surf_list(front->interf);
	    print_correspond_hyper_surf_list((*newfront)->interf);
	}
	if (front->node_propagate != NULL) 
	{
	    start_clock("node_propagate");
	    set_corresponds_for_node_prop(front->interf,(*newfront)->interf);
	    oldn = first_node(front->interf);
	    while (oldn != NULL) 
	    {
	        newn = correspond_node(oldn);
	        if (debugging("crx_status"))
	            print_linked_node_list((*newfront)->interf);
	        status = (newn != NULL) ?
	            (*front->node_propagate)(front,wave,oldn,newn,&rp,
	        			     dt,dt_frac,flag,NULL) : GOOD_NODE;

	        if (debugging("crx_status"))
	        if (is_bad_status(status) &&
	          (point_in_buffer(Coords(oldn->posn),front->rect_grid) == YES))
	        {
	            print_node_status("WARNING in advance_front2d(), "
	                              "node_propagation returns ",status,"\n");
	            (void) printf("Problem occurs in buffer zone - ignoring\n");
	            if (set_node_states_and_continue(oldn,newn,front))
	                status = GOOD_NODE;
	        }

	        switch (status) 
	        {
	        case GOOD_NODE:
	            oldn = adv_node_loop_after_good_prop(oldn,newn,&rp);
	            break;
	        case PSEUDOCROSS_NODE_NODE:
	            debug_print("PSEUDOCROSS","PSEUDOCROSS case\n");
	            oldn = reorder_node_loop(oldn,newn);
	            break;
	        case CROSS_NODE_NODE:
	        case BIFURCATION_NODE:
	            debug_print("CROSS","CROSS case\n");
	            oldn = next_node(oldn);
	            break;
	        case CROSS_PAST_CURVE_NODE:
	            print_node_status("WARNING in advance_front2d(), "
	                              "node_propagate failed with status ",
				      status,"\n");
	            print_node(oldn);
	            if (debugging("CROSS_PAST"))
	            {
	                (void) printf("Cross past curve case\n"
	                              "dt_frac = %g\n",*dt_frac);
	                (void) printf("Reducing time step\n");
	            }
		    status = node_modify_time_step(oldn,front,dt_frac,
					           MODIFY_TIME_STEP);
	            free_rp_list(&rp);
	            goto sync_prop_stat1;
	        case MODIFY_TIME_STEP_NODE:
	            (void) printf("WARNING in advance_front2d(), "
	                          "node_propagate returns "
	                          "MODIFY_TIME_STEP_NODE\n");
	            free_rp_list(&rp);
		    status = node_modify_time_step(oldn,front,NULL,
						   MODIFY_TIME_STEP);
	            goto sync_prop_stat1;
	        case REPEAT_TIME_STEP_NODE:
	            (void) printf("WARNING in advance_front2d(), "
	                          "node_propagate returns "
	                          "REPEAT_TIME_STEP_NODE\n");
	            free_rp_list(&rp);
		    status = node_modify_time_step(oldn,front,NULL,
					           REPEAT_TIME_STEP);
	            goto sync_prop_stat1;
	        case NO_CROSS_NODE:
	            print_node_status("WARNING in advance_front2d(), "
	                              "node_propagate failed with status ",
	                              status,"\n");
	            print_node(oldn);
	            if (debugging("NO_CROSS"))
	            {
	                (void) printf("No cross case\n");
	                (void) printf("dt_frac = %g\n",*dt_frac);
	                (void) printf("Reducing time step\n");
	            }
	            free_rp_list(&rp);
		    status = node_modify_time_step(oldn,front,dt_frac,
					           MODIFY_TIME_STEP);
	            goto sync_prop_stat1;
	        case ERROR_NODE:
	        default:
	            print_node_status("WARNING in advance_front2d(), "
	                              "node_propagate failed with status ",
	                              status,"\n");
	            print_node(oldn);
	            if (debugging("ERROR_NODE"))
	            {
	                (void) printf("Old interface:\n");
	                print_interface(front->interf);
	                print_correspond_hyper_surf_list(front->interf);
	                (void) printf("New interface:\n");
	                print_interface((*newfront)->interf);
	                print_correspond_hyper_surf_list((*newfront)->interf);
	            }
		    status = node_modify_time_step(oldn,front,dt_frac,
					           ERROR_IN_STEP);
	            free_rp_list(&rp);
	            goto sync_prop_stat1;
	        }
	    } /* end of while (oldn != NULL) */
	    set_correspond_hyper_surf_bdrys_to_NULL(front->interf);
	    set_correspond_hyper_surf_bdrys_to_NULL((*newfront)->interf);
	    if (rp && (front->twodrproblem != NULL)) 
	    {
	        for (rp1 = rp; rp1; rp1 = rp1->prev) 
	        {
	            debug_front("2drp_front",
	                "new between node loop and rp loop",*newfront);
	                    
	            status = (*front->twodrproblem)(front,*newfront,wave,&rp1);

	            /* At this point, rp is nothing more than a valid element
	             * of the list which provides a starting point
	             * for deleting the list.  If we delete an element of
	             * the list in front->twodrproblem (presumably due to
	             * merging two RPROBLEM's), then rp may point to freed
	             * storage and will need to be updated.  rp1 should still
	             * be a valid element of the list.
	             */
	            rp = rp1;

		    if (status != GOOD_STEP)
		    {
	                print_time_step_status("WARNING in advance_front2d(), "
					       "rp failed with status = ",
					       status,"\n");
	                switch (status) 
	                {
	                case GOOD_STEP:
			    break;

		        case REPEAT_TIME_STEP:
	                    break;

	                case MODIFY_TIME_STEP:
		            status = rp_modify_time_step(rp1,front,status);
			    if (status == MODIFY_TIME_STEP)
			    {
	                        *dt_frac = rp1->dt_frac;
	                        if (debugging("2drp"))
	                        {
	                            print_rproblem(rp1);
	                            (void) printf("dt_frac %g\n",*dt_frac);
	                            (void) printf("Reducing time step\n");
	                        }
			        *dt_frac = limit_dt_frac(*dt_frac,front);
			    }
	                    break;

	                case ERROR_IN_STEP:
	                default:
	                    print_rproblem(rp1);
	                    /* Try reducing the time step */
		            status = rp_modify_time_step(rp1,front,status);
	                    if (status == MODIFY_TIME_STEP)
	                        *dt_frac *=
				    TIME_STEP_REDUCTION_FACTOR(front->interf);
	                    break;
	                }
		    }
	            if (status != GOOD_STEP)
			break;
	        }
	        free_rp_list(&rp);
	        debug_front("2drp_front","after 2drp loop",*newfront);
	    }
	    else if (rp) 
	    {
	        for (rp1 = rp; rp1; rp1 = rp1->prev) 
	            print_rproblem(rp1);
	        free_rp_list(&rp);
	        (void) printf("WARNING in advance_front2d(), "
	                      "CROSS code needed\n");
	        status = ERROR_IN_STEP;
	    }

sync_prop_stat1:
	    stop_clock("node_propagate");
	    if (front->pp_grid)
	    	status = syncronize_time_step_status(status,front->pp_grid);
	    if (status != GOOD_STEP)
	        return return_advance_front(front,newfront,status,fname);
	}
	if (*front->max_scaled_propagation > 0.5)
	{
	    (void) printf("WARNING in advance_front2d(), "
	                  "front->max_scaled_propagation = %f\n",
			  *(front->max_scaled_propagation));
	    *dt_frac = 0.4/(*front->max_scaled_propagation);
	    status = MODIFY_TIME_STEP;
	    goto sync_prop_stat2;
	}

	stat = consistent_propagated_loop_orientations(dt,dt_frac,front,wave);
	if (stat == NO)
	{
	    (void) printf("WARNING in advance_front2d(), "
		          "Inconsistent orientation of propagated loop "
	                  "detected after point and node propagations");
	    if (pp_numnodes() > 1)
		(void) printf(" on processor %d\n",pp_mynode());
	    else
		(void) printf("\n");
	}
	if (pp_min_status(stat) == NO)
	{
	    if (stat == YES)
	    {
	        (void) printf("WARNING in advance_front2d(), "
		              "Inconsistent orientation of propagated loop "
	                      "detected on a remote processor "
			      "after point and node propagations ");
	    }
	    status = MODIFY_TIME_STEP;
	    goto sync_prop_stat2;
	}

	/* Make Temp Interface for Tangential Propagation */

	set_node_doubly_linked_list((*newfront)->interf);
	if (front->snd_node_propagate) 
	{
	    start_clock("snd_copy_interface");
	    print_storage("before snd_copy_interface","ADV_storage");
	    tempintfc = (*newfront)->interf;
	    set_size_of_intfc_state(size_of_state(tempintfc));
	    set_add_to_correspond_list(YES);
	    if (((*newfront)->interf = pp_copy_interface(tempintfc)) == NULL)
	    {
	    	(void) printf("WARNING in advance_front2d(), "
		              "unable to copy interface\n");
		status = ERROR_IN_STEP;
		goto sync_prop_stat2;
	    }
	    copy_hypersurface_flags((*newfront)->interf);
	    print_storage("after snd_copy_interface","ADV_storage");
	    stop_clock("snd_copy_interface");
	}
	interpolate_intfc_states((*newfront)->interf) = YES;

	/* Second Propagation for the States Around the Nodes */

	if (front->snd_node_propagate) 
	{
	    start_clock("snd_node_propagate");
	    if (debugging("front"))
	    	(void) printf("Second Loop over Nodes\n");

	    tempn = first_node(tempintfc);
	    newn = first_node((*newfront)->interf);
	    while (newn != NULL)
	    {
	    	(*front->snd_node_propagate)(front,*newfront,wave,
	    				     tempintfc,tempn,newn,dt);
	    	tempn = next_node(tempn);
	    	newn = next_node(newn);
	    }

	    debug_front("snd_front","after snd_node prop",*newfront);
	    stop_clock("snd_node_propagate");
	}

	if (tempintfc)
	    (void) delete_interface(tempintfc);
	print_storage("after delete tempintfc","ADV_storage");

		/* Redistribute the New Front */

	switch (redistribute(*newfront,do_redist,NO)) 
	{
	case	GOOD_REDISTRIBUTION:
	    status = GOOD_STEP;
	    break;
	
	case	UNABLE_TO_UNTANGLE:
	    (void) printf("WARNING in advance_front2d(), "
	                  "redistribution of front failed\n"
	                  "Restarting advance_front2d()\n");
	    *dt_frac = Min_time_step_modification_factor(front);
	    status = MODIFY_TIME_STEP;
	    break;

	case	MODIFY_TIME_STEP_REDISTRIBUTE:
	    (void) printf("WARNING in advance_front2d(), "
	                  "redistribute returns\n"
	                  "\t\tMODIFY_TIME_STEP_REDISTRIBUTE, dt_frac = %g\n",
			  *dt_frac);
	    *dt_frac = Min_time_step_modification_factor(front);
	    status = MODIFY_TIME_STEP;
	    break;
		
	case	BAD_REDISTRIBUTION:
	default:
	    (void) printf("WARNING in advance_front2d(), "
	                  "redistribution of front failed\n");
	    debug_front("ERROR_front","after error",*newfront);
	    *dt_frac = Min_time_step_modification_factor(front);
	    status = MODIFY_TIME_STEP;
	    break;
	}
	if (front->pp_grid)
	    status = syncronize_time_step_status(status,front->pp_grid);
	if (status != GOOD_STEP)
	    return return_advance_front(front,newfront,status,fname);

	Redistribution_count(front) = Redistribution_count(*newfront);
	(*newfront)->step = front->step + 1;
	(*newfront)->time = front->time + dt;
	debug_front("redist_front","after redistribution",*newfront);

	/* Communicate topologically propagated front */
	if (scatter_normally_propagated_front == YES)
	{
	    start_clock("scatter_front");
	    if (!scatter_front(*newfront))
	    {
	    	(void) printf("WARNING in advance_front2d(), "
	    	              "scatter_front() failed for "
	    	              "normally propagated front\n");
	    	scatter_normally_propagated_front = NO;
	    	scatter_tangentially_propagated_front = NO;
	    	(void) delete_interface((*newfront)->interf);
	    	(*newfront)->interf = NULL;
	    	goto begin_advance_front2d;
	    }
	    stop_clock("scatter_front");
	}

	debug_front("node_front","after node loop",*newfront);
	if (debugging("front"))
	{
	    print_correspond_hyper_surf_list(front->interf);
	    print_correspond_hyper_surf_list((*newfront)->interf);
	}

	if (front->mass_consv_diagn_driver)
	    (*front->mass_consv_diagn_driver)(front,wave,dt);

	if (debugging("bond_lengths"))
	    check_bond_lengths((*newfront)->interf);

	/* Check for the geometric orientation of loops */

	/* ONLY check loops that will not be deleted !!!! */
	delete_small_loops(*newfront);

		/* Delete non-boundary curves that lie  */
		/* fully on or exterior to the boundary */

	delete_exterior_curves(*newfront,front->interf);
	intfc_delete_fold_back_bonds(*newfront);
	debug_front("dec_front","after delete_exterior_curves:",*newfront);

	interpolate_intfc_states((*newfront)->interf) = YES;

	/* Make Temp Interface for Tangential Propagation */

	if (front->tan_curve_propagate) 
	{
	    start_clock("snd_copy_interface");
	    print_storage("before snd_copy_interface","ADV_storage");
	    tempintfc = (*newfront)->interf;
	    set_size_of_intfc_state(size_of_state(tempintfc));
	    set_add_to_correspond_list(YES);
	    if (((*newfront)->interf = pp_copy_interface(tempintfc)) == NULL)
	    {
	    	(void) printf("WARNING in advance_front2d(), "
		              "unable to copy interface\n");
		status = ERROR_IN_STEP;
		goto sync_prop_stat2;
	    }
	    copy_hypersurface_flags((*newfront)->interf);
	    interpolate_intfc_states((*newfront)->interf) = YES;
	    print_storage("after snd_copy_interface","ADV_storage");
	    stop_clock("snd_copy_interface");
	}

	/* Tangential Sweep for States on the Curves */

	if (front->tan_curve_propagate) 
	{
	    start_clock("tan_curve_propagate");
	    if (debugging("front"))
	    	(void) printf("Second Loop over Curves\n");
	    for (c = tempintfc->curves; c && *c; ++c)
	    {
	    	tempc = *c;
	    	newc = correspond_curve(tempc);
	    	(*front->tan_curve_propagate)(front,*newfront,
	    				      tempintfc,tempc,newc,dt);
	    }
	    debug_front("tcp_front","after tan_curve_propagate:",*newfront);
	    stop_clock("tan_curve_propagate");
	}
	if (tempintfc)
	    (void) delete_interface(tempintfc);
	print_storage("after delete tempintfc","ADV_storage");


		/* Provide robustness for untangle algorithms */

		/*   delete remnants of scalar physical   */
		/*  curves sticking to NEUMANN boundaries */
		/* Add to delete_exterior_curves()? */

	if (pp_min_status(delete_phys_remn_on_bdry(*newfront)) == NO)
	{
	    (void) printf("WARNING in advance_front2d(), "
	                  "delete_phys_remn_on_bdry() detected error\n");
	    debug_front("ERROR_front","after error",*newfront);
	    *dt_frac = Min_time_step_modification_factor(front);
	    status = MODIFY_TIME_STEP;
	    goto sync_prop_stat2;
	}
	debug_front("dspr_front",
		    "after 1st delete_phys_remn_on_bdry():",*newfront);

sync_prop_stat2:
	if (front->pp_grid)
	    status = syncronize_time_step_status(status,front->pp_grid);
	if (status != GOOD_STEP)
	    return return_advance_front(front,newfront,status,fname);

	/* Communicate tangentially propagated front */
	if (scatter_tangentially_propagated_front == YES)
	{
	    start_clock("scatter_front");
	    if (!scatter_front(*newfront))
	    {
	    	(void) printf("WARNING in advance_front2d(), "
	    	              "scatter_front() failed for "
	    	              "tangentially propagated front\n");
	    	scatter_normally_propagated_front = NO;
	    	scatter_tangentially_propagated_front = NO;
	    	(void) delete_interface((*newfront)->interf);
	    	(*newfront)->interf = NULL;
	    	goto begin_advance_front2d;
	    }
	    stop_clock("scatter_front");
	}

	if (status != GOOD_STEP)
	    return return_advance_front(front,newfront,status,fname);


		/* 	Post-process newfront->interf	   */
		/* Provide robustness after redistribution */
		/*   for node propagate on next time step  */

		/* Delete non-boundary curves that lie  */
		/* fully on or exterior to the boundary */

	delete_exterior_curves(*newfront,front->interf);
	debug_front("dec_front","after delete_exterior_curves:",*newfront);

		/*  delete remnants of scalar physical    */
		/* curves sticking to NEUMANN boundaries  */
		/* Add to delete_exterior_curves()? */

	if (pp_min_status(delete_phys_remn_on_bdry(*newfront)) == NO)
	{
	    (void) printf("WARNING in advance_front2d(), "
	                  "delete_phys_remn_on_bdry() detected error\n");
	    debug_front("ERROR_front","after error",*newfront);
	    *dt_frac = Min_time_step_modification_factor(front);
	    status = MODIFY_TIME_STEP;
	    return return_advance_front(front,newfront,status,fname);
	}
	debug_front("dspr_front",
		    "after 2nd delete_phys_remn_on_bdry():",*newfront);


	/* These guys keep sneaking through !! */
	/* This should be the most effective place for this call */
	/* Brent - I believe it is better to have the function at
	*  the end of advance_front2d() applied to the newfront
	*  instead of at the beginning applied to front.
	*  In general our policy should be never to modify the
	*  old interface data.
	*/
	delete_small_loops(*newfront);
	debug_front("dsloop_front","after delete_small_loops():",*newfront);

	test_for_mono_comp_curves((*newfront)->interf);

	/* Check if post processing has changed topology */

	intfc_modified = (*newfront)->interf->modified;
	pp_global_lmax(&intfc_modified,1L);
	if (intfc_modified)
	{
	    if (!scatter_front(*newfront))
	    {
	    	(void) printf("WARNING in advance_front2d(), "
	    	              "final scatter_front() failed\n");
	    	*dt_frac = Max_time_step_modification_factor(front);
	        return return_advance_front(front,newfront,
		                            MODIFY_TIME_STEP,fname);
	    }
	    stat = make_bond_comp_lists((*newfront)->interf);
	    if (pp_min_status(stat) == FUNCTION_FAILED)
	    {
	    	screen("ERROR in advance_front2d(), "
	    	       "make_bond_comp_lists() failed\n");
	    	clean_up(ERROR);
	    }
	}

	return return_advance_front(front,newfront,GOOD_STEP,fname);
}		/*end advance_front2d*/
Beispiel #19
0
/*ARGSUSED*/
LOCAL int advance_front1d(
	double		dt,
	double		*dt_frac,
	Front		*front,
	Front		**newfront,
	POINTER		wave)
{
	POINT              *oldp, *newp;
	HYPER_SURF_ELEMENT *oldhse, *newhse;
	HYPER_SURF         *oldhs, *newhs;
	INTERFACE          *intfc_old, *intfc_new;
	int		   status;
	double              V[MAXD];
	boolean		   has_tracked_points;
	static const char	   *fname = "advance_front1d";

	debug_print("front","Entered %s(step %d time %g dt %g)\n",fname,
				front->step,front->time,dt);
	debug_front("old_front","into advance front",front);

	*newfront = copy_front(front);
	Interface_redistributed(*newfront) = NO;

	has_tracked_points = (front->interf->points != NULL) ? YES : NO;
	if (pp_max_status(has_tracked_points) == NO)
	{
	    set_size_of_intfc_state(size_of_state(front->interf));
	    set_copy_intfc_states(YES);
	    (*newfront)->interf = pp_copy_interface(front->interf);
	    status = ((*newfront)->interf != NULL) ? GOOD_STEP : ERROR_IN_STEP;
	    return return_advance_front(front,newfront,status,fname);
	}

	start_clock("propagate");

		/* Initialize Newfront */

	start_clock("init_new_front");
	set_size_of_intfc_state(size_of_state(front->interf));
	set_copy_intfc_states(NO);
	set_add_to_correspond_list(YES);
	(*newfront)->interf = pp_copy_interface(front->interf);
	if ((*newfront)->interf == NULL)
	{
	    (void) printf("ERROR in advance_front1d(), "
			  "unable to copy interface\n");
	    return return_advance_front(front,newfront,ERROR_IN_STEP,fname);
	}
	stop_clock("init_new_front");

		/* Propagate the points */

	set_propagation_limits(front,*newfront);
	set_copy_intfc_states(YES);
	intfc_old = front->interf;
	intfc_new = (*newfront)->interf;

	(void) next_point(intfc_old,NULL,NULL,NULL);
	(void) next_point(intfc_new,NULL,NULL,NULL);
	while (next_point(intfc_old,&oldp,&oldhse,&oldhs) && 
	       next_point(intfc_new,&newp,&newhse,&newhs))
	{
	    point_propagate(front,wave,oldp,newp,oldhse,oldhs,dt,V);
	}
	copy_hypersurface_flags(intfc_new);
	debug_front("pt_front","after point propagate",*newfront);

	switch (redistribute(*newfront,YES,NO)) 
	{
	case	GOOD_REDISTRIBUTION:
	    status = GOOD_STEP;
	    break;
	
	case	MODIFY_TIME_STEP_REDISTRIBUTE:
	    (void) printf("WARNING in advance_front1d(), redistribution "
			  "of front failed, reducing time step\n");
	    debug_front("ERROR_front","after error",*newfront);
	    *dt_frac = max(Min_time_step_modification_factor(front),*dt_frac);
	    status = MODIFY_TIME_STEP;
	    break;

	case	UNABLE_TO_UNTANGLE:
	case	BAD_REDISTRIBUTION:
	default:
	    (void) printf("WARNING in advance_front1d(), "
	                  "redistribution of front failed\n");
	    debug_front("ERROR_front","after error",*newfront);
	    *dt_frac = Min_time_step_modification_factor(front);
	    status = ERROR_IN_STEP;
	    break;
	}
	debug_front("redist_front","after redistribute",*newfront);
	if (status != GOOD_STEP)
	    return return_advance_front(front,newfront,status,fname);
	if (!scatter_front(*newfront))
	{
	    (void) printf("WARNING in advance_front1d(), "
	    	          "scatter_front() failed for "
	    	          "normally propagated front\n");
	    return return_advance_front(front,newfront,ERROR_IN_STEP,fname);
	}

	(*newfront)->step = front->step + 1;
	(*newfront)->time = front->time + dt;
	interpolate_intfc_states(intfc_new) = YES;
	set_size_of_intfc_state(size_of_state(intfc_new));

	if (intfc_new->modified)
	    (void) make_point_comp_lists(intfc_new);

	stop_clock("propagate");
	debug_front("new_front","from advance front",*newfront);
	return return_advance_front(front,newfront,status,fname);
}		/*end advance_front1d*/
Beispiel #20
0
void obj_update( void )
{   
//  affect_data*          affect;
//  obj_data*                obj;
//  obj_data*            content  = NULL;
//  obj_data*       content_next;
//  obj_clss_data*          fire;
//  oprog_data*            oprog;
//  room_data*              room;
//  char*                message;
  struct timeval         start;
  
  gettimeofday( &start, NULL );

  /*
  for( obj = obj_list; obj != NULL; obj = obj->next ) {
    if( obj->valid != OBJ_DATA || obj->array == NULL )
      continue;
    for( oprog = obj->pIndexData->oprog; oprog != NULL;
      oprog = oprog->next ) {
      if( ( oprog->trigger == TRIGGER_RANDOM )
        && number_range( 0, 999 ) < oprog->value ) {
        var_ch     = character( obj->array );
        var_room   = room( obj->array );
        var_obj    = obj;
        var_mob    = NULL;
        execute( oprog );
        break;
        }
      }
    }
  */
  /*
  for( obj = obj_list; obj != NULL; obj = obj->next ) {
    if( obj->valid != OBJ_DATA )
      continue;

    for( int i = obj->affected.size-1; i >= 0; i-- ) {
      affect = obj->affected[i];
      if( affect->duration > 0 && --affect->duration == 0 )
        remove_affect( obj, affect );     
      }

    room = ( obj->array == NULL ? NULL : obj->array->room( ) );

    if( room == NULL || obj->timer <= 0 || --obj->timer > 0 ) 
      continue;

    for( oprog = obj->pIndexData->oprog; oprog != NULL; oprog = oprog->next )
      if( oprog->trigger == OPROG_TRIGGER_TIMER ) {
        var_obj  = obj;
        var_room = room;
        execute( oprog );
        break;
        }

    if( oprog != NULL )
      continue;

    if( obj->pIndexData->item_type == ITEM_FIRE ) {
      if( ( fire = get_obj_index( obj->value[1] ) ) != NULL 
        && ( content = create( fire ) ) != NULL )
        put_obj( content, room );
      obj->Extract( ); 
      return;
      }

    switch( obj->pIndexData->item_type ) {
     default: 
      message = "%s vanishes.";
      break;

     case ITEM_FOUNTAIN:
      message = "%s dries up."; 
      break;

     case ITEM_CORPSE_NPC:
     case ITEM_CORPSE_PC:
      message = "%s rots, and is quickly eaten by a grue.";
      break;

     case ITEM_FOOD:
      message = "%s decomposes.";
      break;
      }

    fsend_room( room, message, obj );
  */
    /*
    if( obj->pIndexData->item_type == ITEM_CORPSE_PC ) {
      for( content = obj->contents; content != NULL;
        content = content_next ) {
        content_next = content->next_content;
        if( number_range( 1, 3 ) != 3 ) {
          remove( content, content->number ); 
          put_obj( content, room );
          }
        }
      }

    obj->Extract( );
    }
    */

  pulse_time[ TIME_OBJ_LOOP ] = stop_clock( start );  

  return;
}
Beispiel #21
0
void DUAL_ELLIPTIC_SOLVER::solve1d(double *soln)
{
	int index,index_nb[2],size;
	double k_nb[2];
	double rhs,coeff[2];
	int I,I_nb[2];
	int i,j,ii,jj,l,icoords[MAXD];
	COMPONENT comp;
	double aII;
	int num_nb;
	GRID_DIRECTION dir[2] = {WEST,EAST};
	boolean use_neumann_solver = YES;
	PetscInt num_iter = 0;
	double rel_residual = 0.0;
	HYPER_SURF *hs;
	double crx_coords[MAXD];
        int status;
	POINTER intfc_state;
	int icrds_max[MAXD],icrds_min[MAXD];

	if (debugging("trace"))
	    (void) printf("Entering DUAL_ELLIPTIC_SOLVER::solve1d()\n");
	PETSc solver;
	solver.Create(ilower, iupper-1, 3, 3);
	solver.Reset_A();
	solver.Reset_b();
	solver.Reset_x();
	size = iupper - ilower;
	max_soln = -HUGE;
	min_soln = HUGE;

        for (i = cimin; i <= cimax; i++)
	{
	    index  = d_index1d(i,ctop_gmax);
	    comp = ctop_comp[index];
	    I = i_to_I[i];
	    if (I == -1) continue;
	    I_nb[0] = i_to_I[i-1];
	    I_nb[1] = i_to_I[i+1];
	    icoords[0] = i;

	    get_dual_D(icoords,k_nb);

	    num_nb = 0;
	    for (l = 0; l < 2; ++l)
	    {
		status = (*findStateAtCrossing)(front,icoords,dir[l],comp,
                                &intfc_state,&hs,crx_coords);
		if (status != CONST_V_PDE_BOUNDARY)
		    num_nb++;
	    	coeff[l] = k_nb[l]/(top_h[l/2]*top_h[l/2]); 
	    }

	    rhs = source[index];

	    aII = 0.0;
	    for (l = 0; l < 2; ++l)
	    {
		if (num_nb == 0) break;
		status = (*findStateAtCrossing)(front,icoords,dir[l],comp,
                                &intfc_state,&hs,crx_coords);
		if (status == NO_PDE_BOUNDARY)
                {
                    solver.Set_A(I,I_nb[l],coeff[l]);
                    aII += -coeff[l];
                }
                else if (status == CONST_P_PDE_BOUNDARY)
                {
		    rhs += -coeff[l]*getStateVar(intfc_state);
                    aII += -coeff[l];
		    use_neumann_solver = NO;
                }
	    }
	    /*
	     * This change reflects the need to treat point with only one
	     * interior neighbor (a convex point). Not sure why PETSc cannot
	     * handle such case. If we have better understanding, this should
	     * be changed back.
	     */
	    if(num_nb > 0)
	    {
                solver.Set_A(I,I,aII);
	    }
            else
            {
		(void) printf("WARNING: isolated value!\n");
                solver.Set_A(I,I,1.0);
		rhs = soln[index];
            }
            solver.Set_b(I,rhs);
	}
	use_neumann_solver = pp_min_status(use_neumann_solver);
	
	solver.SetMaxIter(40000);
	solver.SetTol(1e-10);

	start_clock("Petsc Solver");
	if (use_neumann_solver)
	{
	    (void) printf("\nUsing Neumann Solver!\n");
	    if (size < 6)
	    {
	    	(void) printf("Isolated small region for solve2d()\n");
		stop_clock("Petsc Solver");
	    }
	    solver.Solve_withPureNeumann();
	    solver.GetNumIterations(&num_iter);
	    solver.GetFinalRelativeResidualNorm(&rel_residual);
	    if(rel_residual > 1)
	    {
		(void) printf("\n The solution diverges! The residual "
		       "is %g. Solve again using GMRES!\n",rel_residual);
		solver.Reset_x();
		solver.Solve_withPureNeumann_GMRES();
		solver.GetNumIterations(&num_iter);
		solver.GetFinalRelativeResidualNorm(&rel_residual);
	    }

	}
	else
	{
	    (void) printf("\nUsing non-Neumann Solver!\n");
	    solver.Solve();
	    solver.GetNumIterations(&num_iter);
	    solver.GetFinalRelativeResidualNorm(&rel_residual);

	    if(rel_residual > 1)
	    {
		(void) printf("\n The solution diverges! The residual "
		       "is %g. Solve again using GMRES!\n",rel_residual);
		solver.Reset_x();
		solver.Solve_GMRES();
		solver.GetNumIterations(&num_iter);
		solver.GetFinalRelativeResidualNorm(&rel_residual);
	    }

	}
	stop_clock("Petsc Solver");

	double *x;
	FT_VectorMemoryAlloc((POINTER*)&x,size,sizeof(double));
	solver.Get_x(x);

	if (debugging("PETSc"))
	    (void) printf("In poisson_solver(): "
	       		"num_iter = %d, rel_residual = %g \n", 
			num_iter, rel_residual);
	
        for (i = cimin; i <= cimax; i++)
	{
	    index = d_index1d(i,ctop_gmax);
	    I = i_to_I[i];
	    if (I == -1) continue;
	    else soln[index] = x[I-ilower];
	    if (max_soln < soln[index]) 
	    {
		icrds_max[0] = i;
		max_soln = soln[index];
	    }
	    if (min_soln > soln[index]) 
	    {
		icrds_min[0] = i;
		min_soln = soln[index];
	    }
	}
	FT_ParallelExchCompGridArrayBuffer(soln,front,NULL);

	pp_global_max(&max_soln,1);
	pp_global_min(&min_soln,1);

	if (debugging("step_size"))
	{
	    (void) printf("Max solution = %20.14f occuring at: %d\n",
			max_soln,icrds_max[0]);
	    checkSolver(icrds_max,YES);
	    (void) printf("Min solution = %20.14f occuring at: %d\n",
			min_soln,icrds_min[0]);
	    checkSolver(icrds_min,YES);
	}

	if (debugging("elliptic_error"))
	{
	    double error,max_error = 0.0;
            for (i = cimin; i <= cimax; i++)
	    {
		icoords[0] = i;
		if (i_to_I[i] == -1) continue;
		error = checkSolver(icoords,NO);
		if (error > max_error) 
		{
		    max_error = error;
		    icrds_max[0] = i;
		}
	    }
	    (void) printf("In dual elliptic solver:\n");
	    (void) printf("Max relative elliptic error: %20.14f\n",max_error);
	    (void) printf("Occuring at (%d)\n",icrds_max[0]);
	    error = checkSolver(icrds_max,YES);
	}
	FT_FreeThese(1,x);
	if (debugging("trace"))
	    (void) printf("Leaving DUAL_ELLIPTIC_SOLVER::solve1d()\n");
}	/* end solve1d */
Beispiel #22
0
LOCAL int second_node_propagate2d(
	float    dt,
	float    *dt_frac,
	Front    *front,
	Front    **newfront,
	POINTER  wave)
{
	NODE 	   *tempn,*newn;
	INTERFACE  *tempintfc;
	bool	   stat;
	int        status = GOOD_STEP;
	long       intfc_modified;
	const char *fname = "second_node_propagate2d()";

	debug_print("front","Entered %s(step %d time %g dt %g)\n",fname,
	        	        front->step,front->time,dt);

	/* Make Temp Interface for Second/Tangential Propagation */


	if ( front->interf == NULL || front->interf->nodes == NULL )
	    return GOOD_STEP;

	set_node_doubly_linked_list((*newfront)->interf);

	if (front->snd_node_propagate) 
	{
	    start_clock("snd_copy_interface");
	    print_storage("before snd_copy_interface","ADV_storage");
	    tempintfc = (*newfront)->interf;
	    set_size_of_intfc_state(size_of_state(tempintfc));
	    set_add_to_correspond_list(YES);
	    (*newfront)->interf = copy_interface(tempintfc);
	    copy_hypersurface_flags((*newfront)->interf);
	    interpolate_intfc_states((*newfront)->interf) = YES;
	    print_storage("after snd_copy_interface","ADV_storage");
	    stop_clock("snd_copy_interface");
	}
      
	/* Second Propagation for the States Around the Nodes */

	if (front->snd_node_propagate) 
	{
	    start_clock("snd_node_propagate");
	    if (debugging("front"))
	    	(void) printf("Second Loop over Nodes\n");

	    tempn = first_node(tempintfc);
	    newn = first_node((*newfront)->interf);
	    while (newn != NULL)
	    {
	    	(*front->snd_node_propagate)(front,*newfront,wave,
	    				     tempintfc,tempn,newn,dt);
	    	tempn = next_node(tempn);
	    	newn = next_node(newn);
	    }

	    debug_front("snd_front","after snd_node prop",*newfront);
	    stop_clock("snd_node_propagate");
	}

	if (tempintfc)
	    (void) delete_interface(tempintfc);
	print_storage("after delete tempintfc","ADV_storage");

	if (status != GOOD_STEP)
	    return return_advance_front(front,newfront,status,fname);
	return return_advance_front(front,newfront,GOOD_STEP,fname);
}		/*end tangnt_advance_front2d*/
Beispiel #23
0
/*ARGSUSED*/
EXPORT	void	u_pp_send(
	int	   tag,
	POINTER	   buf,
	size_t	   len,
	int	   node,
	const char *file,
	int	   line)
{
#if defined(__MPI__)
	static	byte	*msg_buf = NULL;
	int	mpi_return_status;
#endif /* defined(__MPI__) */

	if (debugging("pp_clock"))
	    start_clock("pp_send");
	if (DEBUG)
	{
	    (void) printf("Node %d sending message with tag %d ",
			  pp_mynode(),tag);
	    (void) printf("and len %d to node %d, ",(int)len,node);
	    (void) printf("File %s, line %d\n",file,line);
	}

	pp_okay_to_proceed("u_pp_send","no message sent");

#if defined(__MPI__)

	if (msg_buf == NULL)
	{
	    uni_array(&msg_buf,MSG_BUF_SIZE,sizeof(byte));
	    mpi_return_status = MPI_Buffer_attach(msg_buf,(int)MSG_BUF_SIZE);
	    (void) printf("In first call to u_pp_send(), ");
	    (void) printf("setting the buffer size to %lu bytes.\n",
	    	          MSG_BUF_SIZE);
	    if (mpi_return_status != MPI_SUCCESS)
	    {
	    	screen("ERROR in u_pp_send(), "
	    	       "MPI_Buffer_attach failed, "
	    	       "mpi_return_status = %d\n",mpi_return_status);
		clean_up(ERROR);
	    }
	}
	mpi_return_status = MPI_Bsend(buf,(int)len,MPI_BYTE,
				      node,tag,FronTier_COMM);

	if (mpi_return_status != MPI_SUCCESS)
	{
	    screen("ERROR in u_pp_send(), MPI_Send() failed, "
	           "mpi_return_status = %d\n",mpi_return_status);
	    clean_up(ERROR);
	}

#else /* defined(__MPI__) */

	COMMAND_NOT_IMPLEMENTED("u_pp_send","scalar mode");

#endif /* defined(__MPI__) */

	if (debugging("pp_clock"))
	    stop_clock("pp_send");
	DEBUG_LEAVE(u_pp_send)
}		/*end u_pp_send*/
Beispiel #24
0
int main(int argc, char * argv[])
{
   int err = 0;
   LayerLoc loc;

   const int nloops = 1000;

   PV::Communicator * comm = new PV::Communicator(&argc, &argv);

   const int rank = comm->commRank();

   const int nxProc = comm->numCommColumns();
   const int nyProc = comm->numCommRows();

   const int commRow = comm->commRow();
   const int commCol = comm->commColumn();

   if (rank == 0) {
      fprintf(stderr, "\n[0]: nxProc==%d nyProc==%d commRow==%d commCol==%d numNeighbors==%d\n\n", nxProc, nyProc, commRow, commCol, comm->numberOfNeighbors());
   }

   loc.nx = 128;
   loc.ny = 128;

   loc.nxGlobal = nxProc * loc.nx;
   loc.nyGlobal = nyProc * loc.ny;

   // this info not used for send/recv
   loc.kx0 = 0; loc.ky0 = 0;

   loc.nPad = 16;
   const int nxBorder = loc.nPad;
   const int nyBorder = loc.nPad;

   int numItems = (2*nxBorder + loc.nx) * (2*nyBorder + loc.ny);

   MPI_Datatype * datatypes = comm->newDatatypes(&loc);

   // create a local portion of the "image"
   float * image = new float [numItems];

   int k0 = commCol * loc.nx + commRow * loc.ny * loc.nxGlobal;
   int sy = 2 * nxBorder + loc.nx;

   for (int ky = 0; ky < loc.ny; ky++) {
      int k = k0 + ky * loc.nxGlobal;
      float * buf = image + nxBorder + (ky + nyBorder) * sy;
      for (int kx = 0; kx < loc.nx; kx++) {
         buf[kx] = (float) k++;
      }
   }

#ifdef PV_USE_MPI
   MPI_Barrier(MPI_COMM_WORLD);
#endif

   start_clock();
   double start = MPI_Wtime();

   for (int n = 0; n < nloops; n++) {
      comm->exchange(image, datatypes, &loc);
   }

#ifdef PV_USE_MPI
   MPI_Barrier(MPI_COMM_WORLD);
#endif

   stop_clock();
   double elapsed = MPI_Wtime() - start;

   if (rank == 0) {
      float cycle_time = (1000 * elapsed) / nloops;
      fprintf(stderr, "\n[0]: number of send/recv cycles == %d\n", nloops);
      fprintf(stderr, "[0]: time per send/recv cycle   == %f ms\n", cycle_time);
      fprintf(stderr, "[0]: elapsed time (MPI_Wtime)   == %f s\n\n", (float) elapsed);
   }

   delete datatypes;
   delete comm;

   return err;
}
Beispiel #25
0
int main( int argc, char** argv )
{
  char* index_path;
  char* todo;
  int max = INT32_MAX;
  int64_t chunk_size = 1000;
  if( argc != 3 && argc != 4) usage(argv[0]);

  index_path = argv[1];
  todo = argv[2];
  if( argc==4 ) chunk_size = max = atoi(argv[3]);

  {
    error_t err;
    index_locator_t loc;
    femto_server_t srv;
    int64_t nresults = 0;

    printf("Reading queries\n");
    read_queries(stdin);

    // start the server.
    err = femto_start_server_err(&srv, 0);
    die_if_err( err );

    // Get the locator for the index we're using.
    err = femto_loc_for_path_err(&srv, index_path, &loc);
    die_if_err( err );

    if( 0 == strcmp(todo, "-singlecount") ) {
      printf("Starting single count\n");
      start_clock();
      for( int i = 0; i < nqueries; i++ ) {
        err = parallel_count(&srv, loc, 1, &qlen[i], &queries[i], &count[i], NULL);
        die_if_err(err);
      }
      stop_clock();
      print_timings("single count queries", nqueries);
    } else if( 0 == strcmp(todo, "-count") ) {
      printf("Starting count\n");
      start_clock();

      err = parallel_count(&srv, loc, nqueries, qlen, queries, count, NULL);
      die_if_err(err);
      stop_clock();
      nresults = 0;
      for( int i = 0; i < nqueries; i++ ) {
        nresults += count[i];
        //printf("pat#%i %i occs\n", i, (int) count[i]);
      }
      print_timings("parallel count queries", nqueries);
      printf("Counted %" PRIi64 " results\n", nresults);
    } else if( 0 == strcmp(todo, "-singlelocate") ) {
      printf("Single locate\n");
      start_clock();
      for( int i = 0; i < nqueries; i++ ) {
        offsets[i] = NULL;
        err = serial_locate(&srv, loc, 1, &qlen[i], &queries[i], max, &noccs[i], &offsets[i]);
        //err = parallel_locate(&srv, loc, 1, &qlen[i], &queries[i], max, &noccs[i], &offsets[i]);
        die_if_err(err);
        free(offsets[i]);
        offsets[i] = NULL;
      }
      stop_clock();
      nresults = 0;
      for( int i = 0; i < nqueries; i++ ) {
        nresults += noccs[i];
      }
      print_timings("single locate queries", nqueries);
      print_timings("single locate results", nresults);
    } else if( 0 == strcmp(todo, "-locate") ) {
      start_clock();
      err = parallel_locate(&srv, loc, nqueries, qlen, queries, max, noccs, offsets);
      die_if_err(err);
      stop_clock();

      nresults = 0;
      for( int i = 0; i < nqueries; i++ ) {
        nresults += noccs[i];
        //printf("pat#%i %i occs\n", i, (int) noccs[i]);
        free(offsets[i]);
      }
      print_timings("parallel locate queries", nqueries);
      print_timings("parallel locate results", nresults);
    } else if( 0 == strcmp(todo, "-chunklocate") ) {
      int64_t first, last, current, end;

      printf("Chunk locate\n");
      start_clock();
      for( int i = 0; i < nqueries; i++ ) {
        //printf("Chunk locate - count\n");
        // first do the count.
        err = parallel_count(&srv, loc, 1, &qlen[i], &queries[i], &count_first[i], &count_last[i]);
        die_if_err(err);

        // now do the locate in chunks.
        first = count_first[i];
        last = count_last[i];
        noccs[i] = 1 + last - first;

        for( current = first; current <= last; current += chunk_size)
        {
          end = current + chunk_size - 1;
          if( end > last ) end = last;
          offsets[i] = malloc(sizeof(int64_t) * (1+end-current));
          //printf("Chunk locate: range %" PRIi64 " - %" PRIi64 "\n", current, end);
          err = parallel_locate_range(&srv, loc, current, end, offsets[i]);
          die_if_err(err);
          free(offsets[i]);
          offsets[i] = NULL;
        }

      }
      stop_clock();
      nresults = 0;
      for( int i = 0; i < nqueries; i++ ) {
        nresults += noccs[i];
      }
      print_timings("chunk locate queries", nqueries);
      print_timings("chunk locate results", nresults);
    } else if ( 0 == strcmp(todo, "-paralleldocuments") ) {
      parallel_query_t ctx;

      printf("Parallel document locate\n");
      start_clock();

      err = setup_parallel_query(&ctx, NULL, loc, sizeof(string_results_query_t), nqueries);
      die_if_err(err);
      for( int i = 0; i < nqueries; i++ ) {
        err = setup_string_results_query((string_results_query_t*) ith_query(&ctx, i),
                  NULL, loc, chunk_size, RESULT_TYPE_DOCUMENTS,
                  qlen[i], queries[i]);
        die_if_err(err);
      }

      err = femto_run_query(&srv, (query_entry_t*) &ctx);
      die_if_err(err);

      nresults = 0;
      for( int i = 0; i < nqueries; i++ ) {
        string_results_query_t* q = (string_results_query_t*) ith_query(&ctx, i);
        nresults += q->results.results.num_documents;
        results_destroy(&q->results.results);
      }

      stop_clock();
      print_timings("parallel document locate queries", nqueries);
      print_timings("parallel document locate results", nresults);
    } else if ( 0 == strcmp(todo, "-documents") ) {
      string_results_query_t q;

      printf("Document locate\n");
      start_clock();

      for( int i = 0; i < nqueries; i++ ) {
        err = setup_string_results_query(&q,
                  NULL, loc, chunk_size, RESULT_TYPE_DOCUMENTS,
                  qlen[i], queries[i]);
        die_if_err(err);

        err = femto_run_query(&srv, (query_entry_t*) &q);
        die_if_err(err);

        nresults += q.results.results.num_documents;
        results_destroy(&q.results.results);
      }

      stop_clock();
      print_timings("document locate queries", nqueries);
      print_timings("document locate results", nresults);

    }

    /*printf("Block requests: %" PRIi64 " faults %" PRIi64 "\n",
           uu->stats.block_requests, sst->stats.block_faults);
     */

    femto_stop_server(&srv);
  }

  if( 0 ) {
    int i,j;
    if( noccs ) {
      for( i = 0; i < nqueries; i++ ) {
        if( noccs[i] ) {
          for( j = 0; j < noccs[i] && j < max; j++ ) {
            printf("%i %i/%i %li\n", i, j, noccs[i], (long int) offsets[i][j]);
          }
        }
      }
    }
  }

  return 0;
}
Beispiel #26
0
/**
 * Called by layer 1 - physical, when a frame has arrived.
 *
 * This function has no return value. It must handle all
 * problems itself because the physical layer isn't able
 * to handle errors.
 *
 * NOTE:
 * Link layer error correction and flow control must be considered
 * here. You will certainly need several helper functions because
 * you will need to perform retransmissions after a timeout.
 */
void l2_recv( int device, const char* buf, int length ) {

  const struct L2Header* hdr_pointer;
  const char* l3buf;
  int src_mac_address;
  int dst_mac_address;
  int seq_nr;
  int ack_nr;
  unsigned char frame_type;
  int err;
  
  hdr_pointer = (const struct L2Header*)buf;
  src_mac_address  = ntohl(hdr_pointer->src_mac_address);
  dst_mac_address  = ntohl(hdr_pointer->dst_mac_address);
  seq_nr = ntohl(hdr_pointer->seq_nr);
  ack_nr = ntohl(hdr_pointer->ack_nr);
  frame_type = hdr_pointer->frame_type;
   
  link_entry_t *link;
  // Lookup the link
  int   i;
  for(i = 0; i < MAX_ADDRESSES; i++) {
    if(mac_to_device_map[i].phys_device == device) {
      link = &mac_to_device_map[i];
      break;
    }
  }
  if(i == MAX_ADDRESSES) {
    fprintf( stderr, "MAC address not found in l2_send\n" );
    return;
  }   

  // Determine what kind of frame this is
  if(frame_type == 0x0) { // Normal data frame
    
    // Check if it's a ACK frame first.
    if(seq_nr == -1) {
      
      while(ack_nr >= link->sending_ack_nr) {
        // Stop timer & free buffers
        int buffer_index = link->sending_ack_nr % link->sending_buffer_size;
        
        stop_clock(link, link->sending_ack_nr);
        
        free(link->sending_buffer[buffer_index]);
        link->sending_buffer[buffer_index] = NULL;
        link->sending_buffer_length[buffer_index] = 0;

        increment_seq_nr(&link->sending_ack_nr);
      }      
      // It is safe to return here, since we don't use piggybacking
      return;
    }else if(seq_nr >= link->receive_ack && seq_nr <= link->receive_seq_nr) {
      // Seq_nr in window range.
      if(link->receiving == false) {
        // Initiate buffer and set receiving to true
        link->receive_buffer = safe_malloc(link->receive_buffer_size * sizeof(char*));
        link->receive_buffer_length = safe_malloc(link->receive_buffer_size * sizeof(int));

        memset(link->receive_buffer, 0, 
               link->receive_buffer_size * sizeof(char*)); // Set pointers to 0
        int i;
        for(i = 0; i < link->receive_buffer_size; i++) {
          link->receive_buffer_length[i] = 0;
        }

        link->sent_nak = safe_malloc(link->receive_buffer_size);
        if(link->receive_buffer == 0) {
          fprintf(stderr, "Not enough memory in l2_recv\n");
          return;
        }
        link->receiving = true;
      }
      // Put it in the buffer if it's not allready there.
      l3buf = buf + sizeof(struct L2Header);
      int l3buf_length = length - sizeof(struct L2Header);
      int buffer_index = seq_nr % link->receive_buffer_size;
      
      if(link->receive_buffer[buffer_index] == NULL) {
        link->receive_buffer[buffer_index] = safe_malloc(l3buf_length);
        memcpy(link->receive_buffer[buffer_index], l3buf, l3buf_length);
        
        link->receive_buffer_length[buffer_index] = l3buf_length; // The length of the buf 
      }
      
      buffer_index = link->receive_ack % link->receive_buffer_size;
      if(seq_nr > link->receive_ack && link->sent_nak[buffer_index] == false) { // Send NAK
        l2_send_nak(link, link->receive_ack);
        link->sent_nak[buffer_index] = true;

        return;
      }else if(seq_nr < link->receive_ack) {// If the seq_nr is older than the oldest excpected.
        l2_send_ack(link, link->receive_ack - 1);
        return;
      
      }else {
        int ack = seq_nr;
        boolean delivered = false;
        int buffer_index = link->receive_ack % link->receive_buffer_size;
        
        while(link->receive_buffer[buffer_index] != NULL && 
              link->receive_buffer_length[buffer_index] > sizeof(struct L2Header)) {
          // Try to deliver it to l3
          
          l3buf = link->receive_buffer[buffer_index];
          
          err = l3_recv(dst_mac_address, l3buf, link->receive_buffer_length[buffer_index]);
          if(err <= 0) {
            break;
          }else if(err > 0) {
            // Succsessfull delivery
            int buffer_index = link->receive_ack % link->receive_buffer_size;
            
            free(link->receive_buffer[buffer_index]);
            link->receive_buffer[buffer_index] = NULL;
            link->sent_nak[buffer_index] = false;
            link->receive_buffer_length[buffer_index] = 0;

            // Increment the seq_nr's
            increment_seq_nr(&link->receive_ack);
            increment_seq_nr(&link->receive_seq_nr);
            
            ack = link->receive_ack;
            delivered = true;
          }
        }
        if(delivered) {
          l2_send_ack(link, ack - 1);
          return;
        }else 
          return;
      }
    }       
  }else if(frame_type == 0x1) { // NAK frame
    // Send frame & restart timer
    struct L2Header *header;
    int buffer_index = seq_nr % link->sending_buffer_size;
    char *buf = link->sending_buffer[buffer_index];
    
    int total_size = link->sending_buffer_length[buffer_index] + sizeof(struct L2Header);
    
    char *l1buf = safe_malloc(total_size);
    memcpy(&l1buf[sizeof(struct L2Header)], buf, sizeof(buf));
    
    header = (struct L2Header*) l1buf;
    header->src_mac_address = htonl(l2_get_local_mac_address());
    header->dst_mac_address = htonl(src_mac_address);
    header->frame_type = 0x0;
    header->seq_nr = htonl(seq_nr);
    header->ack_nr = htonl(-1);
    
    l1_send(link->phys_device, l1buf, total_size);
    return;
    
  }else if(frame_type == 0x2) { // Buffer change alert-frame
    // Unused for now.
  }else if(frame_type == 0x3) { // Transmission finished frame
    // Unused for now.
  }
}