Esempio n. 1
0
int main(int argc, char** argv)
{
    StackDescription_t stkd ;
    Analysis_t         analysis ;
    Output_t           output ;
    ThermalData_t      tdata ;

    // Checks if there are the all the arguments
    ////////////////////////////////////////////////////////////////////////////

    if (argc != 3)
    {
        fprintf(stderr, "Usage: \"%s file.stk smfile.txt\"\n", argv[0]) ;
        return EXIT_FAILURE ;
    }

    // Init StackDescription and parse the input file
    ////////////////////////////////////////////////////////////////////////////

    stack_description_init (&stkd) ;
    analysis_init          (&analysis) ;
    output_init            (&output) ;

    if (parse_stack_description_file (argv[1], &stkd, &analysis, &output) != 0)

        return EXIT_FAILURE ;

    // Init thermal data and fill it using the StackDescription
    ////////////////////////////////////////////////////////////////////////////

    thermal_data_init (&tdata) ;

    Error_t result = thermal_data_build

        (&tdata, &stkd.StackElements, stkd.Dimensions, &analysis) ;

    if (result != TDICE_SUCCESS)
    {
        stack_description_destroy (&stkd) ;
        output_destroy            (&output) ;

        return EXIT_FAILURE ;
    }

    // Run the simulation and print the output
    ////////////////////////////////////////////////////////////////////////////

    system_matrix_print (tdata.SM_A, argv[2]) ;


    // free all data
    ////////////////////////////////////////////////////////////////////////////

    thermal_data_destroy      (&tdata) ;
    stack_description_destroy (&stkd) ;
    output_destroy            (&output) ;

    return EXIT_SUCCESS ;
}
Esempio n. 2
0
static int verbose_output(char *out_name)
{
  output_t *out;
  time_t t;
  char date[32];

  /* Load Test Output file */
  out = output_xml_load(out_name);
  if ( out == NULL )
    return -1;

  printf("  Test Suite: %s\n", out->tree.name);

  t = (time_t) (out->tree.begin / 1000);
  strftime(date, sizeof(date), "%d-%b-%Y %H:%M:%S", localtime(&t));
  printf("  Date: %s\n", date);

  if ( out->tree.description != NULL )
    printf("  Description: %s\n", out->tree.description);
  if ( out->tree.reference != NULL )
    printf("  Reference: %s\n", out->tree.reference);
  if ( out->tree.operator != NULL )
    printf("  Operator: %s\n", out->tree.operator);
  printf("  Number of Test Cases: %d\n", out->stat.ncase);
  printf("    Executed=%d Significant=%d\n", out->stat.executed, out->stat.passed + out->stat.failed + out->stat.inconclusive);
  printf("    PASSED=%d FAILED=%d INCONCLUSIVE=%d SKIP=%d\n", out->stat.passed, out->stat.failed, out->stat.inconclusive, out->stat.skip);
  printf("  Duration: %s\n", report_elapsed(out->stat.elapsed_time));

  /* Free Test Output file descriptor */
  output_destroy(out);

  return 0;
}
Esempio n. 3
0
/*****************************************************************************
 * When masscan is called with the "--readscan" parameter, it doesn't
 * do a scan of the live network, but instead reads scan results from
 * a file. Those scan results can then be written out in any of the
 * other formats. This preserves the original timestamps.
 *****************************************************************************/
void
convert_binary_files(struct Masscan *masscan,
                     int arg_first, int arg_max, char *argv[])
{
    struct Output *out;
    int i;

    out = output_create(masscan, 0);

    /*
     * We don't parse the entire argument list, just a subrange
     * containing the list of files. The 'arg_first' parameter
     * points to the first filename after the '--readscan'
     * parameter, and 'arg_max' is the parameter after
     * the last filename. For example, consider an argument list that
     * looks like:
     *   masscan --foo --readscan file1.scan file2.scan --bar
     * Then arg_first=3 and arg_max=5.
     */
    for (i=arg_first; i<arg_max; i++) {
        parse_file(out, argv[i]);
    }

    output_destroy(out);
}
Esempio n. 4
0
/** Decrease reference count of output
 *
 * Destroys the output if reference count drop to zero.
 *
 * \param o The output.
 * \return The reference count after decrement. Zero means destroyed.
 */
int
output_unref(struct output *o)
{
	assert(o->refcount > 0);

	o->refcount--;

	if (o->refcount == 0) {
		output_destroy(o);

		return 0;
	}

	return o->refcount;
}
Esempio n. 5
0
void output_copy (Output_t *dst, Output_t *src)
{
    output_destroy (dst) ;

    inspection_point_list_copy

        (&dst->InspectionPointListFinal, &src->InspectionPointListFinal) ;

    inspection_point_list_copy

        (&dst->InspectionPointListSlot, &src->InspectionPointListSlot) ;

    inspection_point_list_copy

        (&dst->InspectionPointListStep, &src->InspectionPointListStep) ;
}
Esempio n. 6
0
void solve(void * args) {
	unsigned int it, iterations;
	char checkpoint_file_name[512];

	// Structs for the parameters
	InputParameters * params = (InputParameters *) args;
	FlowParams flow_params;
	FsiParams fsi_params;
	OutputParams output_params;

	// Parse input parameters
	input_parse_input_params(params, &flow_params, &fsi_params, &output_params);

	// Allocate state structs for the flow and particle
	FlowState * flow_state = flow_alloc_state(flow_params.lx, flow_params.ly);
	ParticleState * particle_state = fsi_alloc_state(fsi_params.nodes);
	LbmState * lbm_state = lbm_alloc_state(flow_params.lx, flow_params.ly);

	// State structs for Lyapunov calculation
	LyapunovState * lya_state = NULL;
	FlowState * lya_flow_state = NULL;
	ParticleState * lya_particle_state = NULL;
	LbmState * lya_lbm_state = NULL;

	// Setup output
	output_init(&output_params);

	// Try to initialize the solution from a checkpoint file
	sprintf(checkpoint_file_name, "%s/checkpoint.dat", output_params.output_folder);
	FILE * cp_handle = fopen(checkpoint_file_name, "r");

	if(cp_handle) {
		// Checkpoint file existed, read the file and initialize the states
		int lya_exists;

		read_uint(cp_handle, &it);
		fsi_read_state_binary(cp_handle, particle_state);
		flow_read_state_unformatted(cp_handle, flow_state);
		lbm_read_state_binary(cp_handle, lbm_state);

		read_uint(cp_handle, &lya_exists);
		if(lya_exists) {
			lya_particle_state = fsi_alloc_state(fsi_params.nodes);
			fsi_read_state_binary(cp_handle, lya_particle_state);
			lya_flow_state = flow_alloc_state(flow_params.lx, flow_params.ly);
			flow_read_state_unformatted(cp_handle, lya_flow_state);
			lya_lbm_state = lbm_alloc_state(flow_params.lx, flow_params.ly);
			lbm_read_state_binary(cp_handle, lya_lbm_state);

			lya_state = malloc(sizeof(LyapunovState));
			read_double(cp_handle, &lya_state->d0);
			read_double(cp_handle, &lya_state->cum_sum);
			read_double(cp_handle, &lya_state->lambda);
			read_uint(cp_handle, &lya_state->t0);
		}

		fclose(cp_handle);
	} else {
		// No checkpoint file, initialize normally

		// Print parameter file
		output_write_parameters_to_file(&output_params, params);

		// Initialize from base state
		it = 0;
		fsi_init_state(&fsi_params, particle_state);
		flow_init_state(&flow_params, flow_state);
		lbm_init_state(flow_state, lbm_state);

		// Print initial state
		output_write_state_to_file(0, &output_params, flow_state, particle_state, lya_state);
	}

	// Number of iterations
	iterations = it + output_params.timesteps;

	// Main loop
	while(it < iterations) {
		// Advance the solution
		it += 1;
		if( ! lbm_ebf_step(it, &flow_params, flow_state, particle_state, lbm_state))
			break;

		// Check if the Lyapunov exponent should be calculated
		if(output_params.print_lyapunov) {
			double d, alpha;

			// Initialize Lyapunov calculation stuff, if not already done
			if( ! lya_state) {
				lya_state = malloc(sizeof(LyapunovState));
				lya_state->d0 = 1.0e-4;
				lya_state->cum_sum = 0;
				lya_state->t0 = it;
				lya_state->lambda = 0;

				// Copy states
				lya_lbm_state = lbm_clone_state(lbm_state);
				lya_flow_state = flow_clone_state(flow_state);
				lya_particle_state = fsi_clone_state(particle_state);

				// Perturb the particle state
				lya_particle_state->angle += lya_state->d0;
				fsi_update_particle_nodes(lya_particle_state);

			} else {
				// Advance the perturbed state
				if( ! lbm_ebf_step(it, &flow_params, lya_flow_state, lya_particle_state, lya_lbm_state))
					break;

				// Calculate the distance between the original and perturbed orbit
				double ang_vel = particle_state->ang_vel / flow_params.G;
				double lya_ang_vel = lya_particle_state->ang_vel / flow_params.G;

				d = pow(lya_particle_state->angle - particle_state->angle, 2) + pow((lya_ang_vel - ang_vel), 2);
				alpha = sqrt(d / pow(lya_state->d0, 2));

				//printf("%.18g %.18g\n", (it - lya_state->t0)*flow_params.f / (2*PI), alpha);

				if(((it - lya_state->t0) % output_params.lyapunov_calc_step) == 0 && it != lya_state->t0) {
					// Push the perturbed orbit towards the base orbit
					lya_particle_state->angle = particle_state->angle + (lya_particle_state->angle - particle_state->angle) / alpha;
					lya_particle_state->ang_vel = flow_params.G * (ang_vel + (lya_ang_vel - ang_vel) / alpha);

					// Update particle node positions and reset the flow and lbm state to that of the base state
					unsigned int i;
					#pragma omp parallel
					{
						fsi_update_particle_nodes(lya_particle_state);
						#pragma omp for
						for(i = 0; i < lya_flow_state->lx*lya_flow_state->ly; ++i) {
							lya_flow_state->u[0][i] = flow_params.u_max * ((flow_state->u[0][i]/flow_params.u_max) +
														((lya_flow_state->u[0][i]/flow_params.u_max) - (flow_state->u[0][i]/flow_params.u_max)) / alpha);
							lya_flow_state->u[1][i] = flow_params.u_max * ((flow_state->u[1][i]/flow_params.u_max) +
														((lya_flow_state->u[1][i]/flow_params.u_max) - (flow_state->u[1][i]/flow_params.u_max)) / alpha);
							lya_flow_state->rho[i] = flow_state->rho[i] + (lya_flow_state->rho[i] - flow_state->rho[i]) / alpha;
						}
						lbm_init_state(lya_flow_state, lya_lbm_state);
					}

					// Update the lyapunov exponent
					lya_state->cum_sum += log(alpha);
					lya_state->lambda = lya_state->cum_sum / (lya_flow_state->G*(it - lya_state->t0));
					printf("%d %.12g\n", it-lya_state->t0, lya_state->lambda);
				}
			}
		}

		// Post process the result
		if((it % output_params.output_step) == 0)
			output_write_state_to_file(it, &output_params, flow_state, particle_state, lya_state);
	}

	// Write a checkpoint file so the simulation can be resumed at later times
	cp_handle = fopen(checkpoint_file_name, "w");
	write_uint(cp_handle, it);
	fsi_write_state_binary(cp_handle, particle_state);
	flow_write_state_unformatted(cp_handle, flow_state);
	lbm_write_state_binary(cp_handle, lbm_state);
	if( ! lya_state) {
		write_uint(cp_handle, 0);
	} else {
		write_uint(cp_handle, 1);
		fsi_write_state_binary(cp_handle, lya_particle_state);
		flow_write_state_unformatted(cp_handle, lya_flow_state);
		lbm_write_state_binary(cp_handle, lya_lbm_state);

		write_double(cp_handle, lya_state->d0);
		write_double(cp_handle, lya_state->cum_sum);
		write_double(cp_handle, lya_state->lambda);
		write_uint(cp_handle, lya_state->t0);
	}
	fclose(cp_handle);

	// Clean up
	output_destroy(&output_params);
	fsi_free_state(particle_state);
	lbm_free_state(lbm_state);
	flow_free_state(flow_state);

	if(lya_state) {
		fsi_free_state(lya_particle_state);
		lbm_free_state(lya_lbm_state);
		flow_free_state(lya_flow_state);
		free(lya_state);
	}
}
Esempio n. 7
0
int main (int argc, char** argv)
{
  StackDescription_t stkd ;
  Analysis_t         analysis ;
  Output_t           output ;
  ThermalData_t      tdata ;

  Error_t error ;

  struct timespec t1,t2;
  struct timespec res;
  res.tv_sec=0;
  res.tv_nsec=0;
  Quantity_t server_port ;

  Socket_t server_socket, client_socket ;

  NetworkMessage_t request, reply , tmapReply;

  bool headers = false ;

    /* Checks if all arguments are there **************************************/

  if (argc != 3)
  {
    fprintf (stderr, "Usage: \"%s file.stk server_port\n", argv[0]) ;

    return EXIT_FAILURE ;
  }

  server_port = atoi (argv[2]) ;

  /* Parses stack file (fills stack descrition and analysis) ****************/

  fprintf (stdout, "Preparing stk data ... ") ; fflush (stdout) ;

  stack_description_init (&stkd) ;
  analysis_init          (&analysis) ;
  output_init            (&output) ;
  
    error = parse_stack_description_file (argv[1], &stkd, &analysis, &output) ;

  /* Initialise the compression related data ********************************/

  Quantity_t nflpel_ = get_total_number_of_floorplan_elements (&stkd) ;

  float hist_table_d[nflpel_][HIST_TABLE_SIZE];
  
  int tail_d[nflpel_];
  
  for (unsigned int i = 0; i < nflpel_; i++)
  {
    tail_d[i] = 0;
  
    for (int j = 0; j < HIST_TABLE_SIZE; j++)
      hist_table_d[i][j] = -1.0;
  }

  for(int i=0;i<MAXRES;i++)
    for(int j=0;j<MAXROWS;j++)
      for(int k=0;k<MAXCOLS;k++)
        for(int l=0;l<HIST_TABLE_SIZE;l++)
          histTableMap[i][j][k][l] = -1.0;
  int compressionUsed;



  if (error != TDICE_SUCCESS)    return EXIT_FAILURE ;

  if (analysis.AnalysisType != TDICE_ANALYSIS_TYPE_TRANSIENT)
  {
    fprintf (stderr, "only transient analysis!\n") ;

    goto wrong_analysis_error ;
  }

  fprintf (stdout, "done !\n") ;

  /* Prepares thermal data **************************************************/

  fprintf (stdout, "Preparing thermal data ... ") ; fflush (stdout) ;

  thermal_data_init (&tdata) ;

  error = thermal_data_build

    (&tdata, &stkd.StackElements, stkd.Dimensions, &analysis) ;


  if (error != TDICE_SUCCESS)    goto ftd_error ;

  fprintf (stdout, "done !\n") ;

  /* Creates socket *********************************************************/

  fprintf (stdout, "Creating socket ... ") ; fflush (stdout) ;

  socket_init (&server_socket) ;

  error = open_server_socket (&server_socket, server_port) ;



  if (error != TDICE_SUCCESS)    goto socket_error ;

  fprintf (stdout, "done !\n") ;

  /* Waits for a client to connect ******************************************/

  fprintf (stdout, "Waiting for client ... ") ; fflush (stdout) ;

  socket_init (&client_socket) ;

  error = wait_for_client (&server_socket, &client_socket) ;

  if (error != TDICE_SUCCESS)    goto wait_error ;

  fprintf (stdout, "done !\n") ;

  //float timeForTmap = 0.0;
  /* Runs the simlation *****************************************************/

  do
  {
    network_message_init (&request) ;

    receive_message_from_socket (&client_socket, &request) ;

    switch (*request.Type)
    {

      /**********************************************************************/
      case TDICE_COMPRESSION_USED :
        {
          extract_message_word (&request, &compressionUsed,0);
          break;
        }
      case TDICE_EXIT_SIMULATION :
        {
          network_message_destroy (&request) ;

          goto quit ;
        }

        /**********************************************************************/

      case TDICE_RESET_THERMAL_STATE :
        {
          reset_thermal_state (&tdata, &analysis) ;

          break ;
        }

        /**********************************************************************/

      case TDICE_TOTAL_NUMBER_OF_FLOORPLAN_ELEMENTS :
        {
          network_message_init (&reply) ;

          build_message_head   (&reply, TDICE_TOTAL_NUMBER_OF_FLOORPLAN_ELEMENTS) ;

          Quantity_t nflpel = get_total_number_of_floorplan_elements (&stkd) ;

          insert_message_word (&reply, &nflpel) ;

          send_message_to_socket (&client_socket, &reply) ;

          network_message_destroy (&reply) ;

          break ;
        }

        /**********************************************************************/

      case TDICE_INSERT_POWERS_AND_SIMULATE_SLOT :
        {
          Quantity_t nflpel, index ;

          PowersQueue_t queue ;

          powers_queue_init (&queue) ;

          extract_message_word (&request, &nflpel, 0) ;

          powers_queue_build (&queue, nflpel) ;
          if(compressionUsed)
          {
            unsigned int tmp[3];
            int ret=-1;
            unsigned int compressedWord;
            float power=0.0;
            int readIndex=1;
            index=1;
            initTmp(tmp);
            extract_message_word (&request, &compressedWord,readIndex);
            while(index<=nflpel)
            {
              ret=getNextDecompressedWord(compressedWord,tmp,0);
              switch(ret)
              {
                case WI_DC:
                case WC_DC: 
                  switch(tmp[0])
                  {
                    case 0:
                      power=(int)hist_table_d[index-1][tmp[1]]+(hist_table_d[index-1][tmp[2]]-(int)hist_table_d[index-1][tmp[2]]);
                      break; 
                    case 1:
                      power=tmp[1]+(hist_table_d[index-1][tmp[2]]-(int)hist_table_d[index-1][tmp[2]]);
                      hist_table_d[index-1][tail_d[index-1]]=power;
                      tail_d[index-1]=(tail_d[index-1]+1)%HIST_TABLE_SIZE;
                      break;
                    case 2:
                      power=(int)hist_table_d[index-1][tmp[1]]+((float)tmp[2])/(pow(10,DECIMAL_DIGITS));
                      hist_table_d[index-1][tail_d[index-1]]=power;
                      tail_d[index-1]=(tail_d[index-1]+1)%HIST_TABLE_SIZE;
                      break;
                    case 3:
                      power=tmp[1]+((float)tmp[2])/(pow(10,DECIMAL_DIGITS));
                      hist_table_d[index-1][tail_d[index-1]]=power;
                      tail_d[index-1]=(tail_d[index-1]+1)%HIST_TABLE_SIZE;
                      break;
                  }
                  put_into_powers_queue(&queue,power);
                  index++;
                  initTmp(tmp);
                  if(ret==WC_DC)
                  {
                    readIndex++;
                    extract_message_word (&request, &compressedWord,readIndex);
                  }
                  break;
                case WC_DI:
                  readIndex++;
                  extract_message_word (&request, &compressedWord,readIndex);
                  break;
                default:
                  break;
              }
            }
            ret=getNextDecompressedWord(compressedWord,tmp,1);
          }
          /* NO COMPRESSION *************************************/
          else 
          {
            for (index = 1, nflpel++ ; index != nflpel ; index++)
            {
              float power_value ;

              extract_message_word (&request, &power_value, index) ;

              put_into_powers_queue (&queue, power_value) ;
            }

          }
          error = insert_power_values (&tdata.PowerGrid, &queue) ;

          if (error != TDICE_SUCCESS)
          {
            fprintf (stderr, "error: insert power values\n") ;

            powers_queue_destroy (&queue) ;

            goto sim_error ;
          }

          powers_queue_destroy (&queue) ;

          network_message_init (&reply) ;
          build_message_head   (&reply, TDICE_INSERT_POWERS_AND_SIMULATE_SLOT) ;

          SimResult_t result = emulate_slot

            (&tdata, stkd.Dimensions, &analysis) ;

          insert_message_word (&reply, &result) ;

          send_message_to_socket (&client_socket, &reply) ;

          network_message_destroy (&reply) ;

          if (result != TDICE_SLOT_DONE)
          {
            fprintf (stderr, "error %d: emulate slot\n", result) ;

            goto sim_error ;
          }

          break ;
        }

        /**********************************************************************/

      case TDICE_SEND_OUTPUT :
        {
          OutputInstant_t  instant ;
          OutputType_t     type ;
          OutputQuantity_t quantity ;
          //clock_t Time;          

          extract_message_word (&request, &instant,  0) ;
          extract_message_word (&request, &type,     1) ;
          extract_message_word (&request, &quantity, 2) ;

          network_message_init (&reply) ;
          build_message_head   (&reply, TDICE_SEND_OUTPUT) ;

          float   time = get_simulated_time (&analysis) ;
          Quantity_t n = get_number_of_inspection_points (&output, instant, type, quantity) ;

          insert_message_word (&reply, &time) ;
          insert_message_word (&reply, &n) ;

          if (n > 0)
          {
            error = fill_output_message

              (&output, stkd.Dimensions,
               tdata.Temperatures, tdata.PowerGrid.Sources,
               instant, type, quantity, &reply) ;

            if (error != TDICE_SUCCESS)
            {
              fprintf (stderr, "error: generate message content\n") ;

              network_message_destroy (&reply) ;

              goto sim_error ;
            }
          }
          if(type == TDICE_OUTPUT_TYPE_TMAP && compressionUsed)
          {
            //init histTableMap tailMap for compression
            //New packet tmapReply is being initialised /
            //clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &t1);
            network_message_init (&tmapReply);
            build_message_head (&tmapReply, TDICE_SEND_OUTPUT);

            insert_message_word (&tmapReply, &time);
            insert_message_word (&tmapReply, &n);

            CellIndex_t nrows, ncols;

            int readIndex = 4;

            //get the no of rows and cols from reply packet
            extract_message_word (&reply, &nrows, 2);
            extract_message_word (&reply, &ncols, 3);

            //insert nrows and ncols into my packet
            insert_message_word (&tmapReply, &nrows);
            insert_message_word (&tmapReply, &ncols);

            int ret=-1, f1, f2;
            unsigned int compressedWord, i, j, k, l;
            unsigned int flag=0, intPart, decPart;

            unsigned int tmp[3];
            float temper;

            for(i=0; i<n; i++)
              for(j=0; j<nrows; j++)
                for(k=0; k<ncols; k++)
                {
                  f1 = -1;f2 = -1;

                  extract_message_word (&reply, &temper, readIndex);
                  readIndex++;
                  unsigned int intPartTemper, decPartTemper;
                  getParts (temper, &intPartTemper, &decPartTemper);
                  for (l=0;l<HIST_TABLE_SIZE;l++)
                  {
                    if(histTableMap[i][j][k][l] != -1.0)
                    {
                      getParts (histTableMap[i][j][k][l], &intPart, &decPart);
                      if(intPart == intPartTemper)f1 = l;
                      float val=((float)decPart-decPartTemper);
                      val=val/(float)pow(10,DECIMAL_DIGITS);
                      val=abs (val);
                      if(val <= TOLERANCE)
                        f2=l;
                    }
                  }
                  flag = getFlag (f1,f2);

                  switch (flag)
                  {
                    case 1:
                      histTableMap[i][j][k][tailMap[i][j][k]] = intPartTemper + 
                        (histTableMap[i][j][k][f2] - (int)histTableMap[i][j][k][f2]);
                      tailMap[i][j][k] = (tailMap[i][j][k] + 1)%HIST_TABLE_SIZE;
                      break;

                    case 2:
                      histTableMap[i][j][k][tailMap[i][j][k]] = (int)histTableMap[i][j][k][f1] + 
                        ((float)decPartTemper)/(pow(10,DECIMAL_DIGITS));
                      tailMap[i][j][k] = (tailMap[i][j][k] + 1)%HIST_TABLE_SIZE;
                      break;

                    case 3:
                      histTableMap[i][j][k][tailMap[i][j][k]] = intPartTemper + 
                        ((float)decPartTemper)/(pow(10,DECIMAL_DIGITS));
                      tailMap[i][j][k] = (tailMap[i][j][k] + 1)%HIST_TABLE_SIZE;
                      break;

                    default:
                      break;
                  }
                  getArgsInArray (f1, f2, flag, intPartTemper, decPartTemper, tmp);
                  ret = getNextCompressedWord (tmp[1], tmp[2], flag, &compressedWord, !WRAP_UP);
                  if(ret != WORD_INCOMPLETE)
                    insert_message_word (&tmapReply, &compressedWord);
                }
            switch(ret)
            {
              case WORD_INCOMPLETE:
              case WORD_IN_TEMP:
                getNextCompressedWord (tmp[1], tmp[2], flag, &compressedWord, WRAP_UP);
                insert_message_word (&tmapReply, &compressedWord);
                break;
              default:
                break;
            }
            clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &t1);
            send_message_to_socket (&client_socket, &tmapReply);
            clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &t2);
            diff(t1,t2,&res); 
            network_message_destroy (&reply);
            network_message_destroy (&tmapReply);
          }
          else
          {
            if(type == TDICE_OUTPUT_TYPE_TMAP)
            {
            //Time = clock();            
            clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &t1);
            send_message_to_socket (&client_socket, &reply);
            //timeForTmap +=  ((double)clock() - Time) / CLOCKS_PER_SEC  ;
            clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &t2);
            diff(t1,t2,&res); 
            }
            else
            send_message_to_socket (&client_socket, &reply) ;

            network_message_destroy (&reply) ;
          }
          break ;
        }

        /**********************************************************************/

      case TDICE_PRINT_OUTPUT :
        {
          OutputInstant_t  instant ;

          extract_message_word (&request, &instant,  0) ;

          if (headers == false)
          {
            Error_t error = generate_output_headers

              (&output, stkd.Dimensions, (String_t)"% ") ;

            if (error != TDICE_SUCCESS)
            {
              fprintf (stderr, "error in initializing output files \n ");

              goto sim_error ;
            }

            headers = true ;
          }

          generate_output

            (&output, stkd.Dimensions,
             tdata.Temperatures, tdata.PowerGrid.Sources,
             get_simulated_time (&analysis), instant) ;

          break ;
        }

        /**********************************************************************/

      case TDICE_SIMULATE_SLOT :
        {
          network_message_init (&reply) ;
          build_message_head   (&reply, TDICE_SIMULATE_SLOT) ;

          SimResult_t result = emulate_slot (&tdata, stkd.Dimensions, &analysis) ;

          insert_message_word (&reply, &result) ;

          send_message_to_socket (&client_socket, &reply) ;

          network_message_destroy (&reply) ;

          if (result == TDICE_END_OF_SIMULATION)
          {
            network_message_destroy (&request) ;

            goto quit ;
          }
          else if (result != TDICE_SLOT_DONE)
          {
            fprintf (stderr, "error %d: emulate slot\n", result) ;

            goto sim_error ;
          }

          break ;
        }

        /**********************************************************************/

      case TDICE_SIMULATE_STEP :
        {
          network_message_init (&reply) ;
          build_message_head   (&reply, TDICE_SIMULATE_STEP) ;

          SimResult_t result = emulate_step (&tdata, stkd.Dimensions, &analysis) ;

          insert_message_word (&reply, &result) ;

          send_message_to_socket (&client_socket, &reply) ;

          network_message_destroy (&reply) ;

          if (result == TDICE_END_OF_SIMULATION)
          {
            network_message_destroy (&request) ;

            goto quit ;
          }
          else if (result != TDICE_STEP_DONE && result != TDICE_SLOT_DONE)
          {
            fprintf (stderr, "error %d: emulate step\n", result) ;

            goto sim_error ;
          }

          break ;
        }

        /**********************************************************************/

      default :

        fprintf (stderr, "ERROR :: received unknown message type") ;
    }

    network_message_destroy (&request) ;

  } while (1) ;

  /**************************************************************************/

quit :

  socket_close              (&client_socket) ;
  socket_close              (&server_socket) ;
  thermal_data_destroy      (&tdata) ;
  stack_description_destroy (&stkd) ;
  output_destroy            (&output) ;

  printf("Time taken %d sec %d nsec \n",(int)res.tv_sec,(int)res.tv_nsec);
  return EXIT_SUCCESS ;

sim_error :
  network_message_destroy   (&request) ;
  socket_close              (&client_socket) ;
wait_error :
  socket_close              (&server_socket) ;
socket_error :
  thermal_data_destroy      (&tdata) ;
ftd_error :
wrong_analysis_error :
  stack_description_destroy (&stkd) ;
  output_destroy            (&output) ;

  return EXIT_FAILURE ;
}