Esempio n. 1
0
void
free_outbuf(int fd, int error)
{
  assert(fd_table[fd].keepalive >= 0);


  memset(fd_table[fd].outbuf, 0, MAX_UNIQUE_OUTPUT);
  fd_table[fd].outbufsize = fd_table[fd].outbufwritten = fd_table[fd].X_string_to_write = 0;

#ifdef _PLUG_IN
  /*********************/
  fd_table[fd].bytes_last_sent = 0;
  fd_table[fd].bytes_last_response = 0;
  fd_table[fd].use_plugin_response = FALSE;
  /*********************/
#endif
  if ((!fd_table[fd].keepalive) || (error)) {
    /*  close the connection */
    fd_table[fd].state = 0;
    fd_table[fd].inbufptr = NULL;
    memset(fd_table[fd].inbuf, 0, MAX_REQUEST_STRING);
    fd_table[fd].read_offset = 0;
    close(fd);

#ifdef _PLUG_IN
    /*************************/
    fd_table[fd].response_id = NULL;
    /*************************/
#endif
  } else if (!(strstr(fd_table[fd].inbufptr, SYNTH_REQ_DELIM))) {
    /*  have to read more from the fd as the request in not complete */
    assert(fd_table[fd].state == WRITABLE);
    memset(fd_table[fd].inbuf, 1, fd_table[fd].inbufptr - fd_table[fd].inbuf);
    fd_table[fd].state = READABLE;
    fd_table[fd].keepalive--;
  } else {
    /*  have one more request : create the output */
    assert(fd_table[fd].state == WRITABLE);
    memset(fd_table[fd].inbuf, 1, fd_table[fd].inbufptr - fd_table[fd].inbuf);

#ifdef _PLUG_IN
    /*********************/
    if (plug_in.response_prepare_fcn) {
      fd_table[fd].use_plugin_response =
        (plug_in.response_prepare_fcn) (fd_table[fd].inbuf, fd_table[fd].read_offset, &fd_table[fd].response_id);
    }
    if (!fd_table[fd].use_plugin_response) {
      create_output(fd);
    }
    /*********************/
#else
    create_output(fd);
#endif

    fd_table[fd].keepalive--;
  }
  fd_table[fd].outbufwritten = 0;
}
Esempio n. 2
0
int main() {
	int NUMS[MAX_VALUES];
	FILE* input;
    input = fopen("arrsort_in", "r");
    if (input == NULL) {
        perror("Unable to open the file");
        exit(EXIT_FAILURE);
    }

    int size = create_array(NUMS, input);
    heap_sort(NUMS, size);
    create_output(NUMS, size);

    fclose(input);
}
Esempio n. 3
0
int main(int argc, char *argv[]) 
{
  // Set directory structure
  directory_init(argc, argv);

  // Read input file
  main_read_input();

  // Read and sort output directory for finding files within our time limits
  init_part_files();

  // Get number of particles
  nparts = cgns_read_nparts();

  // Initialize domain and flow arrays
  #ifdef DEBUG
    show_domain();
  #endif

  // Create output directory
  create_output();

  // Loop over time
  //double inparts = 1./nparts;
  //double inFiles = 1./nFiles;
  for (int tt = 0; tt < nFiles; tt++) {
    int sum = cgns_fill_parts(tt);
    printf("t = %lf, sum = %d\n", partFileTime[tt], sum);

    // write to file
    write_mean(tt, sum);
  }

  // Free and exit
  free_vars();
  return EXIT_SUCCESS;
}
int read_integer(char *fname, void* pvApiCtx)
{
    SciErr sciErr;
    //output variable info
    int iRows8					= 0;
    int iCols8					= 0;
    int iRows16					= 0;
    int iCols16					= 0;
    int iRows32					= 0;
    int iCols32					= 0;
    int iRowsu8					= 0;
    int iColsu8					= 0;
    int iRowsu16				= 0;
    int iColsu16				= 0;
    int iRowsu32				= 0;
    int iColsu32				= 0;
    int iPrec					= 0;
    int* piAddr8				= NULL;
    int* piAddr16				= NULL;
    int* piAddr32				= NULL;
    int* piAddru8				= NULL;
    int* piAddru16				= NULL;
    int* piAddru32				= NULL;
    char* pcData				= NULL;
    short* psData				= NULL;
    int* piData					= NULL;
    unsigned char* pucData		= NULL;
    unsigned short* pusData		= NULL;
    unsigned int* puiData		= NULL;
    char* pcDataOut				= NULL;
    short* psDataOut			= NULL;
    int* piDataOut				= NULL;
    unsigned char* pucDataOut	= NULL;
    unsigned short* pusDataOut	= NULL;
    unsigned int* puiDataOut	= NULL;

    //check input/output arguments count
    CheckInputArgument(pvApiCtx, 6, 6);
    CheckOutputArgument(pvApiCtx, 6, 6);

    //get variable address
    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr8);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddru8);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr16);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddru16);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddr32);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    sciErr = getVarAddressFromPosition(pvApiCtx, 6, &piAddru32);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //check variable precision
    sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddr8, &iPrec);
    if (sciErr.iErr || iPrec != SCI_INT8)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //check variable precision
    sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddru8, &iPrec);
    if (sciErr.iErr || iPrec != SCI_UINT8)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //check variable precision
    sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddr16, &iPrec);
    if (sciErr.iErr || iPrec != SCI_INT16)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //check variable precision
    sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddru16, &iPrec);
    if (sciErr.iErr || iPrec != SCI_UINT16)
    {
        printError(&sciErr, 0);
        return 0;
    }
    //check variable precision
    sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddr32, &iPrec);
    if (sciErr.iErr || iPrec != SCI_INT32)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //check variable precision
    sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddru32, &iPrec);
    if (sciErr.iErr || iPrec != SCI_UINT32)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //retrieve dimensions and data
    sciErr = getMatrixOfInteger8(pvApiCtx, piAddr8, &iRows8, &iCols8, &pcData);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //retrieve dimensions and data
    sciErr = getMatrixOfUnsignedInteger8(pvApiCtx, piAddru8, &iRowsu8, &iColsu8, &pucData);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //retrieve dimensions and data
    sciErr = getMatrixOfInteger16(pvApiCtx, piAddr16, &iRows16, &iCols16, &psData);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //retrieve dimensions and data
    sciErr = getMatrixOfUnsignedInteger16(pvApiCtx, piAddru16, &iRowsu16, &iColsu16, &pusData);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //retrieve dimensions and data
    sciErr = getMatrixOfInteger32(pvApiCtx, piAddr32, &iRows32, &iCols32, &piData);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //retrieve dimensions and data
    sciErr = getMatrixOfUnsignedInteger32(pvApiCtx, piAddru32, &iRowsu32, &iColsu32, &puiData);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //alloc and fill new variable
    pcDataOut   = (char*)create_output(2, 1, iRows8, iCols8, (void*)pcData);
    pucDataOut  = (unsigned char*)create_output(4, 1, iRowsu8, iColsu8, (void*)pucData);
    psDataOut   = (short*)create_output(8, 2, iRows16, iCols16, (void*)psData);
    pusDataOut  = (unsigned short*)create_output(16, 2, iRowsu16, iColsu16, (void*)pusData);
    piDataOut   = (int*)create_output(32, 4, iRows32, iCols32, (void*)piData);
    puiDataOut  = (unsigned int*)create_output(64, 4, iRowsu32, iColsu32, (void*)puiData);

    //create new variable
    sciErr = createMatrixOfInteger8(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iRows8, iCols8, pcDataOut);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //create new variable
    sciErr = createMatrixOfUnsignedInteger8(pvApiCtx, nbInputArgument(pvApiCtx) + 2, iRowsu8, iColsu8, pucDataOut);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //create new variable
    sciErr = createMatrixOfInteger16(pvApiCtx, nbInputArgument(pvApiCtx) + 3, iRows16, iCols16, psDataOut);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //create new variable
    sciErr = createMatrixOfUnsignedInteger16(pvApiCtx, nbInputArgument(pvApiCtx) + 4, iRowsu16, iColsu16, pusDataOut);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //create new variable
    sciErr = createMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 5, iRows32, iCols32, piDataOut);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //create new variable
    sciErr = createMatrixOfUnsignedInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 6, iRowsu32, iColsu32, puiDataOut);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    FREE(pcDataOut);
    FREE(pucDataOut);
    FREE(psDataOut);
    FREE(pusDataOut);
    FREE(piDataOut);
    FREE(puiDataOut);


    //assign allocated variables to Lhs position
    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
    AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx) + 3;
    AssignOutputVariable(pvApiCtx, 4) = nbInputArgument(pvApiCtx) + 4;
    AssignOutputVariable(pvApiCtx, 5) = nbInputArgument(pvApiCtx) + 5;
    AssignOutputVariable(pvApiCtx, 6) = nbInputArgument(pvApiCtx) + 6;
    return 0;
}
Esempio n. 5
0
File: ita.c Progetto: LCAD-UFES/MAE
void build_network (void)
{
NUM_ISOLATE_NEURON_LAYERS = 12;
NUM_INPUTS = 2;
NUM_OUTPUTS = 6;
NUM_FILTERS = 2;
srand (5); 
memset((void *) &(nl_ita_lp_f), 0, sizeof(NEURON_LAYER));
nl_ita_lp_f.name = "nl_ita_lp_f";
memset((void *) &(nl_prediction), 0, sizeof(NEURON_LAYER));
nl_prediction.name = "nl_prediction";
memset((void *) &(nl_test), 0, sizeof(NEURON_LAYER));
nl_test.name = "nl_test";
memset((void *) &(nl_result), 0, sizeof(NEURON_LAYER));
nl_result.name = "nl_result";
memset((void *) &(nl_ita2_lp_f), 0, sizeof(NEURON_LAYER));
nl_ita2_lp_f.name = "nl_ita2_lp_f";
memset((void *) &(nl_prediction2), 0, sizeof(NEURON_LAYER));
nl_prediction2.name = "nl_prediction2";
memset((void *) &(ita), 0, sizeof(INPUT_DESC));
ita.name = "ita";
memset((void *) &(ita2), 0, sizeof(INPUT_DESC));
ita2.name = "ita2";
memset((void *) &(out_ita_lp_f), 0, sizeof(OUTPUT_DESC));
out_ita_lp_f.name = "out_ita_lp_f";
memset((void *) &(out_prediction), 0, sizeof(OUTPUT_DESC));
out_prediction.name = "out_prediction";
memset((void *) &(out_test), 0, sizeof(OUTPUT_DESC));
out_test.name = "out_test";
memset((void *) &(out_result), 0, sizeof(OUTPUT_DESC));
out_result.name = "out_result";
memset((void *) &(out_ita2_lp_f), 0, sizeof(OUTPUT_DESC));
out_ita2_lp_f.name = "out_ita2_lp_f";
memset((void *) &(out_prediction2), 0, sizeof(OUTPUT_DESC));
out_prediction2.name = "out_prediction2";

__line = 2;
NEURON_MEMORY_SIZE = 10000;
__line = 4;
TYPE_SHOW = SHOW_FRAME;
__line = 5;
TYPE_MOVING_FRAME = STOP;
__line = 8;
//;
__line = 9;
//;
__line = 11;
//;
__line = 12;
//;
__line = 14;
//;
__line = 16;
//;
__line = 17;
//;
__line = 18;
//;
__line = 19;
//;
__line = 20;
//;
__line = 21;
//;
__line = 22;
//;
__line = 25;
create_neuron_layer (&nl_ita_lp_f, NULL, NOT_SPECIFIED, GREYSCALE_FLOAT, INPUT_WIDTH,INPUT_HEIGHT,DISTRIBUTED_MEMORY, NEURON_MEMORY_SIZE);
__line = 26;
create_neuron_layer (&nl_prediction, &minchinton, GREYSCALE_FLOAT, GREYSCALE_FLOAT, OUT_WIDTH,OUT_HEIGHT,DISTRIBUTED_MEMORY, NEURON_MEMORY_SIZE);
__line = 27;
create_neuron_layer (&nl_test, &minchinton, GREYSCALE_FLOAT, GREYSCALE_FLOAT, OUT_WIDTH,OUT_HEIGHT,DISTRIBUTED_MEMORY, NEURON_MEMORY_SIZE);
__line = 28;
create_neuron_layer (&nl_result, &minchinton, GREYSCALE_FLOAT, GREYSCALE_FLOAT, OUT_WIDTH,OUT_HEIGHT,DISTRIBUTED_MEMORY, NEURON_MEMORY_SIZE);
__line = 30;
create_neuron_layer (&nl_ita2_lp_f, NULL, NOT_SPECIFIED, GREYSCALE_FLOAT, INPUT_WIDTH,INPUT_HEIGHT,DISTRIBUTED_MEMORY, NEURON_MEMORY_SIZE);
__line = 31;
create_neuron_layer (&nl_prediction2, &minchinton, GREYSCALE_FLOAT, GREYSCALE_FLOAT, OUT_WIDTH,OUT_HEIGHT,DISTRIBUTED_MEMORY, NEURON_MEMORY_SIZE);
__line = 34;
create_output (&out_ita_lp_f, INPUT_WIDTH,INPUT_HEIGHT, NULL, 0);
__line = 35;
create_output (&out_prediction, OUT_WIDTH,OUT_HEIGHT, output_handler, " ");
__line = 36;
create_output (&out_test, OUT_WIDTH,OUT_HEIGHT, NULL, 0);
__line = 37;
create_output (&out_result, OUT_WIDTH,OUT_HEIGHT, NULL, 0);
__line = 39;
create_output (&out_ita2_lp_f, INPUT_WIDTH,INPUT_HEIGHT, NULL, 0);
__line = 40;
create_output (&out_prediction2, OUT_WIDTH,OUT_HEIGHT, output_handler, " ");
__line = 43;
create_input (&ita, INPUT_WIDTH,INPUT_HEIGHT, GREYSCALE_FLOAT, 0, REGULAR_PYRAMID, input_generator, input_controler, " ", " ");
__line = 45;
create_input (&ita2, INPUT_WIDTH,INPUT_HEIGHT, GREYSCALE_FLOAT, 0, REGULAR_PYRAMID, input_generator, input_controler, " ", " ");
__line = 49;
create_filter (copy_nl_filter, &nl_ita_lp_f, 1, ita.neuron_layer, "");
__line = 51;
create_filter (copy_nl_filter, &nl_ita2_lp_f, 1, ita2.neuron_layer, "");
__line = 54;
output_connect (&nl_ita_lp_f, &out_ita_lp_f);
__line = 55;
output_connect (&nl_prediction, &out_prediction);
__line = 56;
output_connect (&nl_test, &out_test);
__line = 57;
output_connect (&nl_result, &out_result);
__line = 59;
output_connect (&nl_ita2_lp_f, &out_ita2_lp_f);
__line = 60;
output_connect (&nl_prediction2, &out_prediction2);
__line = 63;
associate_neurons (&nl_prediction, &nl_prediction);
__line = 65;
associate_neurons (&nl_prediction2, &nl_prediction2);
__line = 68;
connect_neurons (GAU2, &nl_ita_lp_f, &nl_prediction, SYNAPSES, 0.0, 9.32433, 0.0, -1,-1,-1,-1, -1,-1,-1,-1, DIFFERENT_INTERCONNECTION_PATTERN);
__line = 74;
connect_neurons (GAU2, &nl_ita2_lp_f, &nl_prediction2, SYNAPSES, 0.0, 9.32433, 0.0, -1,-1,-1,-1, -1,-1,-1,-1, DIFFERENT_INTERCONNECTION_PATTERN);
__line = 77;
create_interpreter_user_function (INT_TYPE, GetRandomReturns, "GetRandomReturns", "%d");
;
__line = 78;
create_interpreter_user_function (INT_TYPE, ShowStatistics, "ShowStatistics", "%d");
;
__line = 79;
create_interpreter_user_function (INT_TYPE, ResetStatistics, "ResetStatistics", "%d");
;
__line = 80;
create_interpreter_user_function (INT_TYPE, SetNetworkStatus, "SetNetworkStatus", "%d");
;
__line = 81;
create_interpreter_user_function (INT_TYPE, LoadReturns, "LoadReturns", "%s");
;
__line = 82;
create_interpreter_user_function (INT_TYPE, LoadDayFileName, "LoadDayFileName", "%s");
;
__line = 83;
create_interpreter_user_function (INT_TYPE, LoadDay, "LoadDay", "%d");
;
__line = 84;
create_interpreter_user_function (INT_TYPE, ShowStatisticsExp, "ShowStatisticsExp", "%d");
;
__line = 85;
create_interpreter_user_function (INT_TYPE, MeanStatisticsExp, "MeanStatisticsExp", "%d");
;
__line = 86;
create_interpreter_user_function (INT_TYPE, SetLongShort, "SetLongShort", "%d");
;
map_layers2id (); 
count_num_neurons (); 
initialise_memory (); 
create_io_windows (); 
}
Esempio n. 6
0
int main(int argc, char *argv[]) {
	struct libtrace_t *input = NULL;
	struct libtrace_out_t *in_write = NULL;
	struct libtrace_out_t *out_write = NULL;
	libtrace_err_t trace_err;
	struct libtrace_packet_t *packet = trace_create_packet();
	
	if (argc < 3) {
		usage(argv[0]);
		return 1;
	}

	input = trace_create(argv[1]);
	if (trace_is_err(input)) {
		trace_err = trace_get_err(input);
		printf("Problem reading input trace: %s\n", trace_err.problem);
		return 1;
	}
	if (trace_start(input)==-1) {
		trace_perror(input,"Unable to start trace: %s",argv[1]);
		return 1;
	}
	
	while(1) {
		if (trace_read_packet(input, packet) < 1)
			break;

		switch(trace_get_direction(packet)) {
			case TRACE_DIR_INCOMING:
				if (!out_write) {
					out_write = create_output(argv[3]);
					if (!out_write)
						return 1;
				}
				if (trace_write_packet(out_write, packet)==-1){
					trace_perror_output(in_write,"write");
					return 1;
				}
				break;
			case TRACE_DIR_OUTGOING:
				if (!in_write) {
					in_write = create_output(argv[2]);
					if (!in_write)
						return 1;
				}
				if (trace_write_packet(in_write, packet)==-1) {
					trace_perror_output(in_write,"write");
					return 1;
				}
				break;
			default:
				ignored++;
		}

	}
	if (out_write)
		trace_destroy_output(out_write);
	if (in_write)
		trace_destroy_output(in_write);
	trace_destroy(input);
	trace_destroy_packet(packet);

	if (ignored)
		fprintf(stderr,"warning: Ignored %" PRIu64 " packets with unknown directions\n",
				ignored);
	
	return 0;
}
int main(int argc, char* argv[])
{
  int ret;

  av_register_all();
  av_log_set_level(AV_LOG_DEBUG);

  if(argc < 3)
  {
    printf("usage : %s <input> <output>\n", argv[0]);
    return 0;
  }

  if(open_input(argv[1]) < 0)
  {
    goto main_end;
  }

  if(create_output(argv[2]) < 0)
  {
    goto main_end;
  }

  // OUTPUT 파일에 대한 정보를 출력합니다.
  av_dump_format(outputFile.fmt_ctx, 0, outputFile.fmt_ctx->filename, 1);

  AVPacket pkt;
  int out_stream_index;

  while(1)
  {
    ret = av_read_frame(inputFile.fmt_ctx, &pkt);
    if(ret == AVERROR_EOF)
    {
      printf("End of frame\n");
      break;
    }

    if(pkt.stream_index != inputFile.v_index && 
      pkt.stream_index != inputFile.a_index)
    {
      av_free_packet(&pkt);
      continue;
    }

    AVStream* in_stream = inputFile.fmt_ctx->streams[pkt.stream_index];
    out_stream_index = (pkt.stream_index == inputFile.v_index) ? 
            outputFile.v_index : outputFile.a_index;
    AVStream* out_stream = outputFile.fmt_ctx->streams[out_stream_index];

    av_packet_rescale_ts(&pkt, in_stream->time_base, out_stream->time_base);

    pkt.stream_index = out_stream_index;

    if(av_interleaved_write_frame(outputFile.fmt_ctx, &pkt) < 0)
    {
      printf("Error occurred when writing packet into file\n");
      break;
    }   
  } // while

  // 파일을 쓰는 시점에서 마무리하지 못한 정보를 정리하는 시점입니다.
  av_write_trailer(outputFile.fmt_ctx);

main_end:
  release();

  return 0;
}
Esempio n. 8
0
// Main ------------------------------------------------------------------------------------------
int main(int argc, char **argv) {

	const Params p(argc, argv);
	CUDASetup setcuda(p.device);
	Timer timer;
	cudaError_t cudaStatus;
	int it_cpu = 0;
	int it_gpu = 0;
	int err = 0;
#ifdef LOGS
	set_iter_interval_print(10);
	char test_info[500];
	snprintf(test_info, 500, "-i %d -g %d -t %d -f %s -l %d\n",p.n_gpu_threads, p.n_gpu_blocks,p.n_threads, p.file_name,p.switching_limit);
	start_log_file("cudaSingleSourceShortestPath", test_info);
	//printf("Com LOG\n");
#endif

	// Allocate
	int n_nodes, n_edges;
//	int n_nodes_o;
	read_input_size(n_nodes, n_edges, p);
	timer.start("Allocation");
	Node * h_nodes = (Node *) malloc(sizeof(Node) * n_nodes);

	//*************************** Alocando Memoria para o Gold *************************************
	Gold * gold = (Gold *) malloc(sizeof(Gold) * n_nodes);
	if (p.mode == 1) {
		// **********************  Lendo O gold *********************************
		read_gold(gold, p);
		// **********************************************************************
	}

	//***********************************************************************************************
	Node * d_nodes;
	cudaStatus = cudaMalloc((void**) &d_nodes, sizeof(Node) * n_nodes);
	Edge * h_edges = (Edge *) malloc(sizeof(Edge) * n_edges);
	Edge * d_edges;
	cudaStatus = cudaMalloc((void**) &d_edges, sizeof(Edge) * n_edges);
	std::atomic_int *h_color = (std::atomic_int *) malloc(
			sizeof(std::atomic_int) * n_nodes);
	int * d_color;
	cudaStatus = cudaMalloc((void**) &d_color, sizeof(int) * n_nodes);
	std::atomic_int *h_cost = (std::atomic_int *) malloc(
			sizeof(std::atomic_int) * n_nodes);
	int * d_cost;
	cudaStatus = cudaMalloc((void**) &d_cost, sizeof(int) * n_nodes);
	int * h_q1 = (int *) malloc(n_nodes * sizeof(int));
	int * d_q1;
	cudaStatus = cudaMalloc((void**) &d_q1, sizeof(int) * n_nodes);
	int * h_q2 = (int *) malloc(n_nodes * sizeof(int));
	int * d_q2;
	cudaStatus = cudaMalloc((void**) &d_q2, sizeof(int) * n_nodes);
	std::atomic_int h_head[1];
	int * d_head;
	cudaStatus = cudaMalloc((void**) &d_head, sizeof(int));
	std::atomic_int h_tail[1];
	int * d_tail;
	cudaStatus = cudaMalloc((void**) &d_tail, sizeof(int));
	std::atomic_int h_threads_end[1];
	int * d_threads_end;
	cudaStatus = cudaMalloc((void**) &d_threads_end, sizeof(int));
	std::atomic_int h_threads_run[1];
	int * d_threads_run;
	cudaStatus = cudaMalloc((void**) &d_threads_run, sizeof(int));
	int h_num_t[1];
	int * d_num_t;
	cudaStatus = cudaMalloc((void**) &d_num_t, sizeof(int));
	int h_overflow[1];
	int * d_overflow;
	cudaStatus = cudaMalloc((void**) &d_overflow, sizeof(int));
	std::atomic_int h_gray_shade[1];
	int * d_gray_shade;
	cudaStatus = cudaMalloc((void**) &d_gray_shade, sizeof(int));
	std::atomic_int h_iter[1];
	int * d_iter;
	cudaStatus = cudaMalloc((void**) &d_iter, sizeof(int));
	cudaDeviceSynchronize();
	CUDA_ERR();
	ALLOC_ERR(h_nodes, h_edges, h_color, h_cost, h_q1, h_q2);
	timer.stop("Allocation");

	// Initialize
	timer.start("Initialization");
	const int max_gpu_threads = setcuda.max_gpu_threads();
	int source;
	read_input(source, h_nodes, h_edges, p);

	for (int i = 0; i < n_nodes; i++) {
		h_cost[i].store(INF);
	}
	h_cost[source].store(0);
	for (int i = 0; i < n_nodes; i++) {
		h_color[i].store(WHITE);
	}
	h_tail[0].store(0);
	h_head[0].store(0);
	h_threads_end[0].store(0);
	h_threads_run[0].store(0);
	h_q1[0] = source;
	h_iter[0].store(0);
	h_overflow[0] = 0;
	h_gray_shade[0].store(GRAY0);
	timer.stop("Initialization");
	//timer.print("Initialization", 1);

	// Copy to device
	timer.start("Copy To Device");
	cudaStatus = cudaMemcpy(d_nodes, h_nodes, sizeof(Node) * n_nodes,
			cudaMemcpyHostToDevice);
	cudaStatus = cudaMemcpy(d_edges, h_edges, sizeof(Edge) * n_edges,
			cudaMemcpyHostToDevice);
	cudaDeviceSynchronize();
	CUDA_ERR();
	timer.stop("Copy To Device");

	for (int rep = 0; rep < p.n_reps; rep++) {

		// Reset
		for (int i = 0; i < n_nodes; i++) {
			h_cost[i].store(INF);
		}
		h_cost[source].store(0);
		for (int i = 0; i < n_nodes; i++) {
			h_color[i].store(WHITE);
		}

		it_cpu = 0;
		it_gpu = 0;

		h_tail[0].store(0);
		h_head[0].store(0);
		h_threads_end[0].store(0);
		h_threads_run[0].store(0);
		h_q1[0] = source;
		h_iter[0].store(0);
		h_overflow[0] = 0;
		h_gray_shade[0].store(GRAY0);

		// if(rep >= p.n_warmup)
		timer.start("Kernel");

#ifdef LOGS
		start_iteration();
#endif

		// Run first iteration in master CPU thread
		h_num_t[0] = 1;
		int pid;
		int index_i, index_o;
		for (index_i = 0; index_i < h_num_t[0]; index_i++) {
			pid = h_q1[index_i];
			h_color[pid].store(BLACK);
			int cur_cost = h_cost[pid].load();
			for (int i = h_nodes[pid].x; i < (h_nodes[pid].y + h_nodes[pid].x);
					i++) {
				int id = h_edges[i].x;
				int cost = h_edges[i].y;
				cost += cur_cost;
				h_cost[id].store(cost);
				h_color[id].store(GRAY0);
				index_o = h_tail[0].fetch_add(1);
				h_q2[index_o] = id;
			}
		}
		h_num_t[0] = h_tail[0].load();
		h_tail[0].store(0);
		h_threads_run[0].fetch_add(1);
		h_gray_shade[0].store(GRAY1);
		h_iter[0].fetch_add(1);
		// if(rep >= p.n_warmup)
		timer.stop("Kernel");

		// Pointers to input and output queues
		int * h_qin = h_q2;
		int * h_qout = h_q1;
		int * d_qin = d_q2;
		int * d_qout = d_q1;

		const int CPU_EXEC = (p.n_threads > 0) ? 1 : 0;
		const int GPU_EXEC =
				(p.n_gpu_blocks > 0 && p.n_gpu_threads > 0) ? 1 : 0;

		// Run subsequent iterations on CPU or GPU until number of input queue elements is 0
		while (*h_num_t != 0) {

			if ((*h_num_t < p.switching_limit || GPU_EXEC == 0)
					&& CPU_EXEC == 1) { // If the number of input queue elements is lower than switching_limit
				it_cpu = it_cpu + 1;
				//   if(rep >= p.n_warmup)
				timer.start("Kernel");

				// Continue until switching_limit condition is not satisfied
				while ((*h_num_t != 0)
						&& (*h_num_t < p.switching_limit || GPU_EXEC == 0)
						&& CPU_EXEC == 1) {

					// Swap queues
					if (h_iter[0] % 2 == 0) {
						h_qin = h_q1;
						h_qout = h_q2;
					} else {
						h_qin = h_q2;
						h_qout = h_q1;
					}

					std::thread main_thread(run_cpu_threads, h_nodes, h_edges,
							h_cost, h_color, h_qin, h_qout, h_num_t, h_head,
							h_tail, h_threads_end, h_threads_run, h_gray_shade,
							h_iter, p.n_threads, p.switching_limit, GPU_EXEC);
					main_thread.join();

					h_num_t[0] = h_tail[0].load(); // Number of elements in output queue
					h_tail[0].store(0);
					h_head[0].store(0);
					if (h_iter[0].load() % 2 == 0)
						h_gray_shade[0].store(GRAY0);
					else
						h_gray_shade[0].store(GRAY1);
				}

				//  if(rep >= p.n_warmup)
				timer.stop("Kernel");

			} else if ((*h_num_t >= p.switching_limit || CPU_EXEC == 0)
					&& GPU_EXEC == 1) { // If the number of input queue elements is higher than or equal to switching_limit
				it_gpu = it_gpu + 1;
				//  if(rep >= p.n_warmup)
				timer.start("Copy To Device");
				cudaStatus = cudaMemcpy(d_cost, h_cost, sizeof(int) * n_nodes,
						cudaMemcpyHostToDevice);
				cudaStatus = cudaMemcpy(d_color, h_color, sizeof(int) * n_nodes,
						cudaMemcpyHostToDevice);
				cudaStatus = cudaMemcpy(d_threads_run, h_threads_run,
						sizeof(int), cudaMemcpyHostToDevice);
				cudaStatus = cudaMemcpy(d_threads_end, h_threads_end,
						sizeof(int), cudaMemcpyHostToDevice);
				cudaStatus = cudaMemcpy(d_overflow, h_overflow, sizeof(int),
						cudaMemcpyHostToDevice);
				cudaStatus = cudaMemcpy(d_q1, h_q1, sizeof(int) * n_nodes,
						cudaMemcpyHostToDevice);
				cudaStatus = cudaMemcpy(d_q2, h_q2, sizeof(int) * n_nodes,
						cudaMemcpyHostToDevice);
				cudaStatus = cudaMemcpy(d_iter, h_iter, sizeof(int),
						cudaMemcpyHostToDevice);
				cudaDeviceSynchronize();
				CUDA_ERR();
				//  if(rep >= p.n_warmup)
				timer.stop("Copy To Device");

				// Continue until switching_limit condition is not satisfied
				while ((*h_num_t != 0)
						&& (*h_num_t >= p.switching_limit || CPU_EXEC == 0)
						&& GPU_EXEC == 1) {

					// Swap queues
					if (h_iter[0] % 2 == 0) {
						d_qin = d_q1;
						d_qout = d_q2;
					} else {
						d_qin = d_q2;
						d_qout = d_q1;
					}

					//  if(rep >= p.n_warmup)
					timer.start("Copy To Device");
					cudaStatus = cudaMemcpy(d_num_t, h_num_t, sizeof(int),
							cudaMemcpyHostToDevice);
					cudaStatus = cudaMemcpy(d_tail, h_tail, sizeof(int),
							cudaMemcpyHostToDevice);
					cudaStatus = cudaMemcpy(d_head, h_head, sizeof(int),
							cudaMemcpyHostToDevice);
					cudaStatus = cudaMemcpy(d_gray_shade, h_gray_shade,
							sizeof(int), cudaMemcpyHostToDevice);
					cudaDeviceSynchronize();
					CUDA_ERR();
					//  if(rep >= p.n_warmup)
					timer.stop("Copy To Device");

					//  if(rep >= p.n_warmup)
					timer.start("Kernel");
					assert(
							p.n_gpu_threads <= max_gpu_threads
									&& "The thread block size is greater than the maximum thread block size that can be used on this device");
					cudaStatus = call_SSSP_gpu(p.n_gpu_blocks, p.n_gpu_threads,
							d_nodes, d_edges, d_cost, d_color, d_qin, d_qout,
							d_num_t, d_head, d_tail, d_threads_end,
							d_threads_run, d_overflow, d_gray_shade, d_iter,
							p.switching_limit, CPU_EXEC,
							sizeof(int) * (W_QUEUE_SIZE + 3));
					cudaDeviceSynchronize();
					CUDA_ERR();
					//  if(rep >= p.n_warmup)
					timer.stop("Kernel");

					// if(rep >= p.n_warmup)
					timer.start("Copy Back and Merge");
					cudaStatus = cudaMemcpy(h_tail, d_tail, sizeof(int),
							cudaMemcpyDeviceToHost);
					cudaStatus = cudaMemcpy(h_iter, d_iter, sizeof(int),
							cudaMemcpyDeviceToHost);
					cudaDeviceSynchronize();
					CUDA_ERR();
					//  if(rep >= p.n_warmup)
					timer.stop("Copy Back and Merge");

					h_num_t[0] = h_tail[0].load(); // Number of elements in output queue
					h_tail[0].store(0);
					h_head[0].store(0);
					if (h_iter[0].load() % 2 == 0)
						h_gray_shade[0].store(GRAY0);
					else
						h_gray_shade[0].store(GRAY1);
				}

				// if(rep >= p.n_warmup)
				timer.start("Copy Back and Merge");
				cudaStatus = cudaMemcpy(h_cost, d_cost, sizeof(int) * n_nodes,
						cudaMemcpyDeviceToHost);
				cudaStatus = cudaMemcpy(h_color, d_color, sizeof(int) * n_nodes,
						cudaMemcpyDeviceToHost);
				cudaStatus = cudaMemcpy(h_threads_run, d_threads_run,
						sizeof(int), cudaMemcpyDeviceToHost);
				cudaStatus = cudaMemcpy(h_threads_end, d_threads_end,
						sizeof(int), cudaMemcpyDeviceToHost);
				cudaStatus = cudaMemcpy(h_overflow, d_overflow, sizeof(int),
						cudaMemcpyDeviceToHost);
				cudaStatus = cudaMemcpy(h_q1, d_q1, sizeof(int) * n_nodes,
						cudaMemcpyDeviceToHost);
				cudaStatus = cudaMemcpy(h_q2, d_q2, sizeof(int) * n_nodes,
						cudaMemcpyDeviceToHost);
				cudaDeviceSynchronize();
				CUDA_ERR();
				// if(rep >= p.n_warmup)
				timer.stop("Copy Back and Merge");
			}
		}

#ifdef LOGS
		end_iteration();
#endif

		// printf("IT CPU:%d\t",it_cpu);
		//printf("IT GPU:%d\n",it_gpu);
		if (p.mode == 1) {
			err = newest_verify(h_cost, n_nodes, n_nodes, gold, it_cpu, it_gpu);
		}		//err=new_verify(h_cost, n_nodes,,it_cpu,it_gpu);

		if (err > 0) {
			printf("Errors: %d\n", err);
			read_input(source, h_nodes, h_edges, p);
			read_gold(gold, p);
		} else {
			printf(".ITERATION %d\n", rep);
		}
#ifdef LOGS
		log_error_count(err);
#endif
		// Ler a entrada novamente
		//read_input(source, h_nodes, h_edges, p);
		//read_gold(gold,p);

	} // end of iteration
#ifdef LOGS
	end_log_file();
#endif
	// timer.print("Allocation", 1);
	//timer.print("Copy To Device", p.n_reps);
	// timer.print("Kernel", p.n_reps);
	// timer.print("Copy Back and Merge", p.n_reps);
	if (p.mode == 0) {
		create_output(h_cost, n_nodes, n_edges, std::string(p.comparison_file));
	}
	// Verify answer
	verify(h_cost, n_nodes, p.comparison_file);

	// Free memory
	timer.start("Deallocation");
	free(h_nodes);
	free(h_edges);
	free(h_color);
	free(h_cost);
	free(h_q1);
	free(h_q2);
	cudaStatus = cudaFree(d_nodes);
	cudaStatus = cudaFree(d_edges);
	cudaStatus = cudaFree(d_cost);
	cudaStatus = cudaFree(d_color);
	cudaStatus = cudaFree(d_q1);
	cudaStatus = cudaFree(d_q2);
	cudaStatus = cudaFree(d_num_t);
	cudaStatus = cudaFree(d_head);
	cudaStatus = cudaFree(d_tail);
	cudaStatus = cudaFree(d_threads_end);
	cudaStatus = cudaFree(d_threads_run);
	cudaStatus = cudaFree(d_overflow);
	cudaStatus = cudaFree(d_iter);
	cudaStatus = cudaFree(d_gray_shade);
	CUDA_ERR();
	cudaDeviceSynchronize();
	timer.stop("Deallocation");
	//timer.print("Deallocation", 1);

	// Release timers
	timer.release("Allocation");
	timer.release("Initialization");
	timer.release("Copy To Device");
	timer.release("Kernel");
	timer.release("Copy Back and Merge");
	timer.release("Deallocation");

	printf("Test Passed\n");
	return 0;
}
Esempio n. 9
0
// Aborts and returns 1 if an error is encountered.
int PackageRenderer::render_package(RenderPackage *package)
{
	int audio_done = 0;
	int video_done = 0;
	int samples_rendered = 0;


	result = 0;
	this->package = package;

// printf(
// "PackageRenderer::render_package: audio s=%lld l=%lld video s=%lld l=%lld\n",
// 	package->audio_start, 
// 	package->audio_end - package->audio_start, 
// 	package->video_start, 
// 	package->video_end - package->video_start);


// FIXME: The design that we only get EDL once does not give us neccessary flexiblity to do things the way they should be donek
	default_asset->video_data = package->video_do;
	default_asset->audio_data = package->audio_do;
	Render::check_asset(edl, *default_asset);
	
	create_output();

	if(!asset->video_data) video_done = 1;
	if(!asset->audio_data) audio_done = 1;

// Create render engine
	if(!result)
	{
		create_engine();

//printf("PackageRenderer::render_package 5 %d\n", result);

// Main loop
		while((!audio_done || !video_done) && !result)
		{
			int need_audio = 0, need_video = 0;




// Calculate lengths to process.  Audio fragment is constant.
			if(!audio_done)
			{
				if(audio_position + audio_read_length >= package->audio_end)
				{
					audio_done = 1;
					audio_read_length = package->audio_end - audio_position;
				}

				samples_rendered = audio_read_length;
				need_audio = 1;
			}

//printf("PackageRenderer::render_package 6 %d\n", samples_rendered);

			if(!video_done)
			{
				if(audio_done)
				{
					video_read_length = package->video_end - video_position;
// Packetize video length so progress gets updated
					video_read_length = (int)MIN(asset->frame_rate, video_read_length);
					video_read_length = MAX(video_read_length, 30);
				}
				else
// Guide video with audio
				{
					video_read_length = Units::to_int64(
						(double)(audio_position + audio_read_length) / 
						asset->sample_rate * 
						asset->frame_rate) - 
						video_position;
				}

// Clamp length
				if(video_position + video_read_length >= package->video_end)
				{
					video_done = 1;
					video_read_length = package->video_end - video_position;
				}

// Calculate samples rendered for progress bar.
				if(audio_done)
					samples_rendered = Units::round((double)video_read_length /
						asset->frame_rate *
						asset->sample_rate);

				need_video = 1;
			}

//printf("PackageRenderer::render_package 1 %d %lld %lld\n", result, audio_read_length, video_read_length);
			if(need_video && !result) do_video();
//printf("PackageRenderer::render_package 7 %d %d\n", result, samples_rendered);
			if(need_audio && !result) do_audio();


			if(!result) set_progress(samples_rendered);





			if(!result && progress_cancelled()) result = 1;

// printf("PackageRenderer::render_package 10 %d %d %d %d\n", 
// audio_read_length, video_read_length, samples_rendered, result);
			if(result) 
				set_result(result);
			else
				result = get_result();
		}

//printf("PackageRenderer::render_package 20\n");
		stop_engine();
//printf("PackageRenderer::render_package 30\n");

		stop_output();
//printf("PackageRenderer::render_package 40\n");


	}



//printf("PackageRenderer::render_package 50\n");
	close_output();
//printf("PackageRenderer::render_package 60\n");


	set_result(result);
//printf("PackageRenderer::render_package 70\n");



	return result;
}
Esempio n. 10
0
int main(int argc, char *argv[]) 
{
  // Set directory structure
  directory_init(argc, argv);

  printf("Initializing...\n"); 
  fflush(stdout);
  // Read input file
  main_read_input();

  // Read and sort output directory for finding files within our time limits
  init_files();

  // Initialize domain and flow arrays
  domain_init(); 

  // Create output directory
  create_output();
  get_sigfigs();

  // Pull initial time step
  tt = 0;
  cgns_fill();

  // Find min and max and set up bins
  minmax(&min_vf, &max_vf, volume_fraction);
  minmax(&min_wp, &max_wp, part_w);
  minmax(&min_ke, &max_ke, part_ke);
  bin_init(min_vf, max_vf, &dBin_vf, &binStart_vf, &binEnd_vf);
  bin_init(min_wp, max_wp, &dBin_wp, &binStart_wp, &binEnd_wp);
  bin_init(min_ke, max_ke, &dBin_ke, &binStart_ke, &binEnd_ke);

  #ifdef DEBUG
    printf("  Bin Start (vf) = %lf\n", binStart_vf);
    printf("  Min (vf) = %lf\n", min_vf);
    printf("  dBin (vf) = %lf\n", dBin_vf);
    printf("  Max (vf) = %lf\n", max_vf);
    printf("  Bin End (vf) = %lf\n", binEnd_vf);
  #endif
    printf("  Bin Start (ke) = %lf\n", binStart_ke);
    printf("  Min (ke) = %lf\n", min_ke);
    printf("  dBin (ke) = %lf\n", dBin_ke);
    printf("  Max (ke) = %lf\n", max_ke);
    printf("  Bin End (ke) = %lf\n", binEnd_ke);

  // normalization for means
  double norm = 1./(dom.Gcc.s3 * nFiles);

  // Loop over time and bin
  printf("Looping...\n"); 
  fflush(stdout);
  int ind, ind_vf, ind_wp;

  for (tt = 0; tt < nFiles; tt++) {
    printf("  Timestep = %d of %d\n", tt+1, nFiles);
    fflush(stdout);
    // Fill data from cgns file
    cgns_fill();

    // Loop over space
    for (int cc = 0; cc < dom.Gcc.s3; cc++) {
      /* Volume Fraction */
      mean_vf += norm*volume_fraction[cc];
      // calculate index
      ind = (volume_fraction[cc] - binStart_vf)/dBin_vf;
      // if ind < 0, make it zero
      // if ind > nBins + 1, make it nBins +1
      ind = ind*(ind >= 0);         
      ind = ind*(ind <= (nBins + 1)) + (nBins + 1)*(ind > (nBins + 1));
      histogram_vf[ind]++;

      ind_vf = ind;

      /* Part Wp */
      mean_wp += norm*part_w[cc];
      ind = (part_w[cc] - binStart_wp)/dBin_wp;
      ind = ind*(ind >= 0);         
      ind = ind*(ind <= (nBins + 1)) + (nBins + 1)*(ind > (nBins + 1));
      histogram_wp[ind]++;

      ind_wp = ind;

      /* Bivariate */
      bihistogram_vf_wp[ind_wp + (nBins + 2)*ind_vf]++;

      /* Kinetic Energy */
      mean_ke += norm*part_ke[cc];
      ind = (part_ke[cc] - binStart_ke)/dBin_ke;
      ind = ind*(ind >= 0);         
      ind = ind*(ind <= (nBins + 1)) + (nBins + 1)*(ind > (nBins + 1));
      histogram_ke[ind]++;
    }

    // keep track of min max mean std for ALL files?
    // have bin padding as an input parameter?

  }
  // write to file
  write_field();

  // Free and exit
  printf("Done!\n");
  free_vars();
  return EXIT_SUCCESS;
}
Esempio n. 11
0
int main(int argc, char *argv[]) 
{
  // Set up batch submission
  #ifdef BATCH
    SIM_ROOT_DIR = (char*) malloc(CHAR_BUF_SIZE * sizeof(char));
    ROOT_DIR = (char*) malloc(CHAR_BUF_SIZE * sizeof(char));

    // arg[0] = program name
    // arg[1] = SIM_ROOT_DIR
    if (argc == 2) {
      sprintf(SIM_ROOT_DIR, "%s", argv[1]);
      sprintf(ROOT_DIR, "%s/f-rec-part-3D", SIM_ROOT_DIR);
    } else if (argc != 2) {
      printf("usage: %s SIM_ROOT_DIR\n", argv[0]);
      exit(EXIT_FAILURE);
    }
    printf("\n SIM_ROOT_DIR = %s\n", SIM_ROOT_DIR);
    printf(" ROOT_DIR = %s\n\n", ROOT_DIR);
  #else           // prevent compiler warning
    argc = argc;
    argv = argv;
  #endif

  // Read input file
  main_read_input();

  // Read and sort output directory for finding files within our time limits
  init_part_files();

  // Get number of particles
  nparts = cgns_read_nparts();

  // Initialize partstruct and flow vars
  parts_init();

  // Initialize domain and flow arrays
  domain_init(); 

  // Allocate arrays
  alloc_arrays();

  // Create output directory
  get_sigfigs();
  create_output();

  /* MAIN LOOP */
  double kl, km, kn;
  int ll, mm, nn, corder;
  // Loop over time
  for (tt = 0; tt < nFiles; tt++) {
    // Fill parts with new info
    cgns_fill_parts();

    // Loop over all coefficients l,m,n (x,y,z)
    for (ll = 0; ll <= orderL; ll++) {
      kl = 2.*PI*ll/dom.xl;
      for (mm = 0; mm <= orderM; mm++) {
        km = 2.*PI*mm/dom.yl;
        for (nn = 0; nn <= orderN; nn++) {
          kn = 2.*PI*nn/dom.zl;
          corder = nn + (orderN + 1)*mm + (orderN + 1)*(orderM + 1)*ll;

          // Calculate coefficients n_lmn
          // TODO: need diff for vfrac
          calc_coeffs(n_lmn, ones, parts, kl, km, kn, corder);
          //printf("n_lmn[%d] = %f + %fi\n", corder, creal(n_lmn[corder]), cimag(n_lmn[corder]));
          // does it make sense to not even store n_lmn?

          // evaluate series for n_lmn at x,y,z
          // TODO: need diff for vfrac
          // TODO: parallelize? probably not, is not TOO slow
          // TODO: is n_rec always real?
          eval_series(n_rec, n_lmn, kl, km, kn, corder);

        }
      }
    }
    // Normalize nq by n to find q
    // make sure to divide by volume...
    //normalize(nu_ces, n_ces);

//  // write to file -- TODO take specific nq_rec as input
    cgns_write_field();
  }
   
  // Free and exit
  free_vars();
  printf("... Done!\n");
  return EXIT_SUCCESS;
}
Esempio n. 12
0
void
read_request(int fd)
{
  int len;
  /*  printf("read_request called \n"); */
  if (!(strstr(fd_table[fd].inbufptr, SYNTH_REQ_DELIM))) {
    /*  the input buffer is delimited by SYNTH_REQ_DELIM */
#ifdef DEBUG
    fprintf(stderr, "read_offset=%d  MAX_REQUEST_STRING=%d  difference=%d\n",
            fd_table[fd].read_offset, MAX_REQUEST_STRING, MAX_REQUEST_STRING - fd_table[fd].read_offset);
    fflush(stderr);
#endif
    if (fd_table[fd].read_offset > (MAX_REQUEST_STRING * 3) / 4) {
      fprintf(stderr, "Warning: Input buffer almost full.  Not reading any more.\n");
      fflush(stderr);
      free_outbuf(fd, 1);
      return;
    }
    len = read(fd, fd_table[fd].inbuf + fd_table[fd].read_offset, MAX_REQUEST_STRING - fd_table[fd].read_offset);
#ifdef DEBUG
    fprintf(stderr, "read returned %d bytes\n", len);
    fflush(stderr);
#endif
    if (len < 0) {
      if (errno == EWOULDBLOCK || errno == EAGAIN)
        return;                 /*  temporary error */
      free_outbuf(fd, 1);
      return;                   /*  badness! */
    }
    if (len == 0) {
      /*  poll said that data available => 0 bytes is bad */
      free_outbuf(fd, 1);
      return;
    }
    if (len > 0) {
      fd_table[fd].read_offset += len;
      /*  printf("inside read loop; the string now is %s \n", fd_table[fd].inbuf); */
    }
  }

  if (!(strstr(fd_table[fd].inbufptr, SYNTH_REQ_DELIM)))
    return;

  if (strstr(fd_table[fd].inbufptr, "LOST")) {
    /* example: "GET LOST length20.html" 
       used by the client to kill the server */
    fprintf(stderr, "SDKtest_server: shutting down because of client request to stop server.\n");

#ifdef _PLUG_IN
    /********************/
    if (plug_in.plugin_finish_fcn) {
      (plug_in.plugin_finish_fcn) ();
    }
    /********************/
#endif

    exit(0);
  }
#ifdef _PLUG_IN
  /***********************/
  if (plug_in.response_prepare_fcn) {
    fd_table[fd].use_plugin_response =
      (plug_in.response_prepare_fcn) (fd_table[fd].inbuf, fd_table[fd].read_offset, &fd_table[fd].response_id);
  }
  if (!fd_table[fd].use_plugin_response) {
    create_output(fd);
  }
#else
  create_output(fd);
  /***********************/
#endif

  fd_table[fd].state = WRITABLE;
}
void Coagulation::coag_simulate()
{
	double coag_cur_state[num_factors] = {};
	double coag_next_state[num_factors] = {};
	double dt[] = { 1.0e-10, 1.0e-8, 1.0e-5 };
	double t_max[] = { 1.0e-8, 1.0e-6, 1.0e0 };
	int incr[] = { 10, 10, 100 };
	double t = 0.0;
	int c = 0;

	Initialize(coag_cur_state);

	//sw.WriteLine("time" + ',' + "XII" + ',' + " XIIa" + ',' + " VIII" + ',' + " VIIIa" + ',' + " IX" + ',' + " IXa" + ',' + " XI" + ',' + " XIa" + ',' + " VII" + ',' + " VIIa" + ',' + " X" + ',' + " Xa" + ',' + "V" + ',' + " Va" + ',' + " Xa_Va" + ',' + " II" + ',' + " IIa" + ',' + " TAT" + ',' + " Fg" + ',' + " F" + ',' + " XF" + ',' + " FDP" + ',' + " D" + ',' + " XIII" + ',' + "XIIIa" + ',' + "Pg" + ',' + "P" + ',' + "PC" + ',' + " APC" + ',' + " Tmod" + ',' + " IIa_Tmod" + ',' + " IXa_VIIIa" + ',' + " TF" + ',' + " VII_TF" + ',' + " VIIa_TF" + ',' + "TFPI" + ',' + "Xa_TFPI" + ',' + " VIIa_TF_Xa_TFPI" + ',' + " PS" + ',' + " APC_PS" + ',' + "Pk" + ',' + "K" + ',' + "VK" + ',' + "VKH2" + ',' + "VKO" + ',' + "VK_p" + ',' + "Awarf" + ',' + "Cwarf" + ',' + "ATIII_Heparin" + ',' + "DP");
	for (size_t i = 0; i < ARRAY_SIZE(dt); i++)
	{
		while (t < t_max[i])
		{
			rk2(coag_next_state, coag_cur_state, dt[i], coag_ode);
			memcpy(coag_cur_state, coag_next_state, sizeof(coag_cur_state));
			t += dt[i];
			c++;

			if (c == incr[i])
			{
				create_output(coag_cur_state, t);
				c = 0;
			}
		}
	}

	std::cout << std::setprecision(15);
	std::cout <<"Fg: " << coag_cur_state[Fg]<< std::endl;
	std::cout <<"F: " << coag_cur_state[F]<< std::endl;
	std::cout <<"XF: " << coag_cur_state[XF]<< std::endl;
	std::cout <<"DegProd: " << coag_cur_state[DegProd]<< std::endl;
	std::cout <<"II: " << coag_cur_state[II]<< std::endl;
	std::cout <<"IIa: " << coag_cur_state[IIa]<< std::endl;
	std::cout <<"IIa_Tmod: " << coag_cur_state[IIa_Tmod] << std::endl;
	std::cout <<"PC: " << coag_cur_state[PC]<< std::endl;
	std::cout <<"APC: " << coag_cur_state[APC]<< std::endl;
	std::cout <<"PS: " << coag_cur_state[PS]<< std::endl;
	std::cout <<"APC_PS: " << coag_cur_state[APC_PS]<< std::endl;
	std::cout <<"TAT: " << coag_cur_state[TAT]<< std::endl;
	std::cout <<"Pk: " << coag_cur_state[Pk]<< std::endl;
	std::cout <<"K: " << coag_cur_state[K]<< std::endl;
	std::cout <<"VII: " << coag_cur_state[VII]<< std::endl;
	std::cout <<"VII_TF: " << coag_cur_state[VII_TF]<< std::endl;
	std::cout <<"VIIa: " << coag_cur_state[VIIa]<< std::endl;
	std::cout <<"VIIa_TF: " << coag_cur_state[VIIa_TF]<< std::endl;
	std::cout <<"VIII: " << coag_cur_state[VIII]<< std::endl;
	std::cout <<"VIIIa: " << coag_cur_state[VIIIa]<< std::endl;
	std::cout <<"IX: " << coag_cur_state[IX]<< std::endl;
	std::cout <<"IXa: " << coag_cur_state[IXa]<< std::endl;
	std::cout <<"IXa_VIIIa: " << coag_cur_state[IXa_VIIIa]<< std::endl;
	std::cout <<"X: " << coag_cur_state[X]<< std::endl;
	std::cout <<"Xa: " << coag_cur_state[Xa]<< std::endl;
	std::cout <<"Xa_Va: " << coag_cur_state[Xa_Va]<< std::endl;
	std::cout <<"Xa_TFPI: " << coag_cur_state[Xa_TFPI]<< std::endl;
	std::cout <<"VIIa_TF_Xa_TFPI: " << coag_cur_state[VIIa_TF_Xa_TFPI]<< std::endl;
	std::cout <<"XI: " << coag_cur_state[XI]<< std::endl;
	std::cout <<"XIa: " << coag_cur_state[XIa]<< std::endl;
	std::cout <<"XII: " << coag_cur_state[XII]<< std::endl;
	std::cout <<"XIIa: " << coag_cur_state[XIIa]<< std::endl;
	std::cout << std::endl;
	std::cout <<"TF: " << coag_cur_state[TF]<< std::endl;
	std::cout <<"CA: " << coag_cur_state[CA]<< std::endl;
}