Ejemplo n.º 1
0
int copy_xdf(const char* genfilename, const char* reffilename, int dstfmt)
{
	struct xdf *dst = NULL, *src = NULL;
	int srcfmt, retcode = -1;

	/* Open the source file*/
	src = xdf_open(reffilename, XDF_READ, XDF_ANY);
	if (src == NULL)
		goto exit;
	xdf_get_conf(src, XDF_F_FILEFMT, &srcfmt, XDF_NOF);

	/* Create the destination file */
	if (dstfmt == XDF_ANY)
		dstfmt = srcfmt;
	dst = xdf_open(genfilename, XDF_WRITE, dstfmt);
	if (dst == NULL)
		goto exit;

	/* Copy the metadata (time, location, channel layout, event types) */
	if (copy_configuration(dst, src))
		goto exit;

	/* Copy channel data */
	if (copy_datastream(dst, src))
		goto exit;

	/* Copy event table */
	if (copy_eventtable(dst, src))
		goto exit;

	retcode = 0;

exit:
	xdf_close(src);
	xdf_close(dst);

	return retcode;
}
EAP_FUNC_EXPORT eap_status_e eap_plugin_server_message_if_c::process_message(eap_process_tlv_message_data_c * const message)
{
	// Parses message data composed of Attribute-Value Pairs.

	EAP_TRACE_DATA_DEBUG(
		m_am_tools,
		EAP_TRACE_FLAGS_NEVER,
		(EAPL("eap_plugin_server_message_if_c::process_message()"),
		message->get_message_data(),
		message->get_message_data_length()));

	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, TRACE_FLAGS_DEFAULT, "returns: eap_plugin_server_message_if_c::process_message()");

	eap_array_c<eap_tlv_header_c> parameters(m_am_tools);

	eap_status_e status = message->parse_message_data(&parameters);
	if (status != eap_status_ok)
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);

		(void) send_error_message(
			status,
			eap_tlv_message_type_function_none);

		return EAP_STATUS_RETURN(m_am_tools, status);
	}

	if (parameters.get_object_count() == 0)
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);

		status = eap_status_illegal_parameter;

		(void) send_error_message(
			status,
			eap_tlv_message_type_function_none);

		return EAP_STATUS_RETURN(m_am_tools, status);
	}

	const eap_tlv_header_c * const function_header = parameters.get_object(eap_message_payload_index_function);
	if (function_header == 0
		|| (function_header->get_type() != eap_tlv_message_type_error
			&& function_header->get_type() != eap_tlv_message_type_function))
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);

		status = eap_status_illegal_parameter;

		(void) send_error_message(
			status,
			eap_tlv_message_type_function_none);

		return EAP_STATUS_RETURN(m_am_tools, status);
	}

	if (function_header->get_type() == eap_tlv_message_type_error)
	{
		status = process_message_type_error(&parameters);
	}
	else // function_header->get_type() == eap_tlv_message_type_function
	{
		eap_tlv_message_type_function_e function(eap_tlv_message_type_function_none);

		status = message->get_parameter_data(function_header, &function);
		if (status != eap_status_ok)
		{
			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);

			(void) send_error_message(
				status,
				eap_tlv_message_type_function_none);

			return EAP_STATUS_RETURN(m_am_tools, status);
		}

		EAP_TRACE_DEBUG(
			m_am_tools, 
			TRACE_FLAGS_DEFAULT, 
			(EAPL("eap_plugin_server_message_if_c::process_message(): this = 0x%08x, message=%d=%s\n"),
			this,
			function,
			eap_process_tlv_message_data_c::get_function_string(function)));

		switch(function)
		{
		case eap_tlv_message_type_function_plugin_get_configuration:
			status = get_configuration(&parameters);
			break;
		case eap_tlv_message_type_function_plugin_set_configuration:
			status = set_configuration(&parameters);
			break;
		case eap_tlv_message_type_function_plugin_copy_configuration:
			status = copy_configuration(&parameters);
			break;
		case eap_tlv_message_type_function_plugin_delete_configuration:
			status = delete_configuration(&parameters);
			break;
		case eap_tlv_message_type_function_plugin_set_index:
			status = set_index(&parameters);
			break;
		case eap_tlv_message_type_function_plugin_get_type_info:
			status = get_type_info(&parameters);
			break;
		case eap_tlv_message_type_function_plugin_invoke_ui:
			status = invoke_ui(&parameters);
			break;
		default:
			EAP_TRACE_ERROR(
				m_am_tools,
				TRACE_FLAGS_DEFAULT,
				(EAPL("ERROR: process_data(): unknown function %d.\n"),
				 function));

			status = eap_status_illegal_parameter;

			EAP_ASSERT_ANYWAY_TOOLS(m_am_tools);
		};

		if (status != eap_status_ok
			&& status != eap_status_success
			&& status != eap_status_pending_request
			&& status != eap_status_completed_request
			&& status != eap_status_drop_packet_quietly)
		{
			(void) send_error_message(
				status,
				function);
		}
	}

	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
	return EAP_STATUS_RETURN(m_am_tools, status);
}
Ejemplo n.º 3
0
/******************************************************************************
 * Main of the parallel sampling sort
 ******************************************************************************/
int main(int argc, char **argv){
    int mpi_size, mpi_rank;
    double t0, t1;
    int is_help;
    char *final_buff;
    unsigned long long rsize;

    MPI_Comm comm = MPI_COMM_WORLD;
    MPI_Init(&argc, &argv);
    MPI_Comm_size(comm, &mpi_size);
    MPI_Comm_rank(comm, &mpi_rank);

    t0 = MPI_Wtime();

    config_t *config = (config_t *)malloc(sizeof(config_t));
    config_t *config_init = (config_t *)malloc(sizeof(config_t));
    init_configuration(config);
    init_configuration(config_init);

    is_help = get_configuration(argc, argv, mpi_rank, config_init);

    // when -h flag is set to seek help of how to use this program
    if (is_help) {
        free_configuration(config);
        free_configuration(config_init);
        MPI_Finalize();
        return 1;
    }

    copy_configuration(config, config_init);

    int ntf, mtf, tstep, nsteps_tot;
    mtf = config->tmin / config->tinterval;
    ntf = config->tmax / config->tinterval + 1;
    if (config->nsteps == 1) {
        nsteps_tot = ntf;
    } else {
        nsteps_tot = config->tmax;
    }

    // Get the particle tags from sorted-by-energy data of the last time frame,
    // and then sort the tags
    int *tags, qindex;
    int row_size, dataset_num, max_type_size, key_value_type;
    char *tracked_particles, *tracked_particles_sum, *package_data;
    dset_name_item *dname_array;
    hsize_t my_data_size, rest_size;
    if (config->tracking_traj) {
        tags = (int *)malloc(config->nptl_traj * sizeof(int));
        char filename_ene[MAX_FILENAME_LEN];
        tstep = (ntf - 1) * config->tinterval;
        snprintf(filename_ene, MAX_FILENAME_LEN, "%s%s%d%s%s%s",
                config->filepath, "/T.", tstep, "/", config->species,
                "_tracer_energy_sorted.h5p");
        if (config->nsteps != 1) tstep--;
        // get particle tags w.r.t some energy
        get_particle_tags(filename_ene, tstep, config->ratio_emax,
                config->nptl_traj, tags);

        // sort the tags
        qsort(tags, config->nptl_traj, sizeof(int), CompareInt32Value);

        // get the indices for Ux and q in the HDF5 file
        snprintf(config->group_name, MAX_FILENAME_LEN, "%s%d", "/Step#", tstep);
        dname_array = (dset_name_item *)malloc(MAX_DATASET_NUM * sizeof(dset_name_item));
        package_data = get_vpic_pure_data_h5(mpi_rank, mpi_size, filename_ene,
            config->group_name, &row_size, &my_data_size, &rest_size, &dataset_num,
            &max_type_size, &key_value_type, dname_array);
        free(package_data);
        qindex = get_dataset_index("q", dname_array, dataset_num);
        config->ux_kindex = get_dataset_index("Ux", dname_array, dataset_num);

        tracked_particles = (char *)malloc(nsteps_tot * config->nptl_traj * row_size);
        for (int j = 0; j < nsteps_tot*config->nptl_traj*row_size; j++) {
            tracked_particles[j] = 0;
        }
        if (mpi_rank == 0) {
            tracked_particles_sum = (char *)malloc(nsteps_tot * config->nptl_traj * row_size);
            for (int j = 0; j < nsteps_tot*config->nptl_traj*row_size; j++) {
                tracked_particles_sum[j] = 0;
            }
        }
    } // if (config->tracking_traj)

    if (config->multi_tsteps) {
        for (int i = mtf; i < ntf; i++) {
            tstep = i * config->tinterval;
            if (mpi_rank == 0) printf("Time Step: %d\n", tstep);
            if (config->reduced_tracer) {
                set_filenames_reduced(tstep, config->filepath, config->species,
                        config->filename, config->group_name, config->filename_sorted,
                        config->filename_attribute, config->filename_meta);
            } else {
                set_filenames(tstep, config_init, config);
            }
            if (config->nsteps == 1) {
                final_buff = sorting_single_tstep(mpi_size, mpi_rank, config, &rsize);
                if (config->tracking_traj) {
                    get_tracked_particle_info(final_buff, qindex, row_size,
                            rsize, i, ntf, tags, config->nptl_traj, tracked_particles);
                }
                if(config->collect_data == 1) {
                    free(final_buff);
                }
            } else {
                for (tstep = (i-1) * config->tinterval; tstep < i*config->tinterval; tstep++) {
                    snprintf(config->group_name, MAX_FILENAME_LEN, "%s%d", "/Step#",
                            tstep);
                    final_buff = sorting_single_tstep(mpi_size, mpi_rank, config, &rsize);
                    if (config->tracking_traj) {
                        get_tracked_particle_info(final_buff, qindex, row_size,
                                rsize, tstep, nsteps_tot, tags, config->nptl_traj,
                                tracked_particles);
                    }
                    if(config->collect_data == 1) {
                        free(final_buff);
                    }
                }
            }
        }
    } else {
        if (mpi_rank == 0) {
            printf("Input filename: %s\n", config->filename);
            printf("Group name: %s\n", config->group_name);
            printf("Output filename: %s\n", config->filename_sorted);
            printf("Meta data filename: %s\n", config->filename_meta);
        }
        set_filenames(config->tstep, config_init, config);

        final_buff = sorting_single_tstep(mpi_size, mpi_rank, config, &rsize);
        if(config->collect_data == 1) {
            free(final_buff);
        }
    }

    MPI_Barrier(MPI_COMM_WORLD);

    if (config->tracking_traj) {
        MPI_Reduce(tracked_particles, tracked_particles_sum,
                nsteps_tot*config->nptl_traj*row_size, MPI_CHAR, MPI_SUM, 0,
                MPI_COMM_WORLD);

        /* Save the particle data. */
        if (mpi_rank == 0) {
            save_tracked_particles(config->filename_traj, tracked_particles_sum,
                    nsteps_tot, config->nptl_traj, row_size, dataset_num, max_type_size,
                    dname_array, tags);
        }
        free(tracked_particles);
        if (mpi_rank == 0) {
            free(tracked_particles_sum);
        }
        free(tags);
        free(dname_array);
    }

    MPI_Barrier(MPI_COMM_WORLD);
    t1 = MPI_Wtime();
    if(mpi_rank == 0) {
        printf("Overall time is [%f]s \n", (t1 - t0));
    }

    free_configuration(config);
    free_configuration(config_init);

    MPI_Finalize();
    return 0;
}