Ejemplo n.º 1
0
static void VS_CC
set_limiter_data(generic_handler_t *gh, filter_id_t id, char *msg,
                 const VSMap *in, VSMap *out, const VSAPI *vsapi)
{
    RET_IF_ERROR(!gh->vi->format, "format is not constant");

    int err;

    int th_min = (int)vsapi->propGetInt(in, "min", 0, &err);
    if (err || th_min < 0) {
        th_min = 0;
    }

    int max = (1 << gh->vi->format->bitsPerSample) - 1;
    int th_max = (int)vsapi->propGetInt(in, "max", 0, &err);
    if (err || th_max > max) {
        th_max = max;
    }

    RET_IF_ERROR(th_min > th_max, "min is larger than max");

    const char *ret = set_alone(gh);
    RET_IF_ERROR(ret, "%s", ret);
    alone_t *ah = (alone_t *)gh->fdata;

    set_lut(ah, th_min, th_max);
}
Ejemplo n.º 2
0
int main(int argc, char ** argv){
	int  rank=0, size=0;
	int  NX = NX_DIM;                // size of 1D array we will write
	double t[NX_DIM];                // this will contain the variables
	MPI_Comm  comm = MPI_COMM_WORLD; // required for ADIOS

	int64_t 	adios_handle;        // the ADIOS file handler
	int retval;
	struct adios_tsprt_opts adios_opts;
	int err_count = 0;

	GET_ENTRY_OPTIONS(adios_opts, "Runs writers. It is recommended to run as many writers as readers.");

	// I assume that I have all required options set in adios_opts

	// sanity check
	assert(NX==NX_DIM);

	// ADIOS initialization
	MPI_Init(&argc, &argv);
	MPI_Comm_rank (comm, &rank);
	MPI_Comm_size (comm, &size);

	SET_ERROR_IF_NOT_ZERO(adios_init(adios_opts.xml_adios_init_filename, comm), err_count);
	RET_IF_ERROR(err_count, rank);

	// init the array that I will transport
	if (gen_1D_array(t, NX, rank) == DIAG_ERR){
		printf("ERROR: Generating 1D array. Quitting ...\n");
		return DIAG_ERR;
	}

	uint64_t adios_groupsize, adios_totalsize;

	// open with the group name as specified in the xml file
	adios_open( &adios_handle, "temperature", FILE_NAME, "w", comm);
	adios_groupsize = 4 + 4 + 4 + 8 * (NX);
	retval=adios_group_size (adios_handle, adios_groupsize, &adios_totalsize);
	fprintf(stderr, "Rank=%d adios_group_size(): adios_groupsize=%" PRIu64 ", adios_totalsize=%" PRIu64 ", retval=%d\n",
			rank, adios_groupsize, adios_totalsize, retval);

	// write; don't check errors for simplicity reasons
	adios_write(adios_handle, "NX", &NX);
	adios_write(adios_handle, "size", &size);
	adios_write(adios_handle, "rank", &rank);
	adios_write(adios_handle, "var_1d_array", t);

	fprintf(stderr, "Rank=%d committed write\n", rank);

	adios_close(adios_handle);

	// clean and finalize the system
	adios_finalize(rank);
	MPI_Finalize();

	return DIAG_OK;
}
Ejemplo n.º 3
0
static void VS_CC
set_levels_data(generic_handler_t *gh, filter_id_t id, char *msg,
                const VSMap *in, VSMap *out, const VSAPI *vsapi)
{
    RET_IF_ERROR(!gh->vi->format, "format is not constant");

    const char *ret = set_alone(gh);
    RET_IF_ERROR(ret, "%s", ret);
    alone_t *ah = (alone_t *)gh->fdata;

    int err;
    int bps = gh->vi->format->bitsPerSample;
    int size = 1 << bps;
    int imin = (int)vsapi->propGetInt(in, "min_in", 0, &err);
    if (err || imin < 0) {
        imin = 0;
    }
    int imax = (int)vsapi->propGetInt(in, "max_in", 0, &err);
    if (err || imax > size - 1) {
        imax = 0xFF << (bps - 8);
    }
    int omin = (int)vsapi->propGetInt(in, "min_out", 0, &err);
    if (err || omin < 0) {
        omin = 0;
    }
    int omax = (int)vsapi->propGetInt(in, "max_out", 0, &err);
    if (err || omax > size - 1) {
        omax = 0xFF << (bps - 8);
    }
    double gamma = vsapi->propGetFloat(in, "gamma", 0, &err);
    if (err || gamma <= 0.0f) {
        gamma = 1.0;
    }

    set_lut(imin, imax, omin, omax, gamma, size, ah->lut);
}
Ejemplo n.º 4
0
int main (int argc, char **argv){
	int rank =0, size =0;
	int NX = 0;
	double *t = NULL;
	// this is an array we expect as a reference array
	double *t_ref = NULL;
	MPI_Comm comm = MPI_COMM_WORLD;
	diag_t diag = DIAG_OK;  // to store the diagnostic information
	struct test_info test_result = {TEST_PASSED, "1D_arr_global_noxml"};
	struct err_counts err = { 0, 0};
	struct adios_tsprt_opts adios_opts;

	GET_ENTRY_OPTIONS(adios_opts,  "Runs readers. It is recommended to run as many readers as writers.");

	// adios read initialization
	MPI_Init( &argc, &argv);
	MPI_Comm_rank (comm, &rank);

	// depending on the method
	SET_ERROR_IF_NOT_ZERO(adios_read_init_method(adios_opts.method, comm, adios_opts.adios_options), err.adios);
	RET_IF_ERROR(err.adios, rank);


	// I will be working with streams so the lock mode is necessary,
	// return immediately if the stream unavailable
	ADIOS_FILE *adios_handle = adios_read_open(FILE_NAME, adios_opts.method, comm, ADIOS_LOCKMODE_NONE, 0.0);
	if ( !adios_handle){
		p_error("Quitting ... (%d) %s\n", adios_errno, adios_errmsg());
		return DIAG_ERR;
	}

	// define portions of data how they will be read
	ADIOS_SELECTION *sel = NULL;
	ADIOS_VARINFO *avi = NULL;


	// for storing the variables
	char buf[STR_BUFFER_SIZE];

	int step = 0;

	// read how many processors wrote that array
	avi = adios_inq_var (adios_handle, "size");
	if (!avi){
		p_error("rank %d: Quitting ... (%d) %s\n", rank, adios_errno, adios_errmsg());
		diag = DIAG_ERR;
		goto close_adios;
	}
	size = *((int*)avi->value);
	adios_free_varinfo(avi);
	avi = NULL;

	// if I run the more readers than writers; just release
	// the excessive readers
	if (rank >= size){
		p_info("rank %d: I am an excessive rank. Nothing to read ...\n", rank);
		diag = DIAG_OK;
		goto close_adios;
	}

	// read the size of the array
	avi = adios_inq_var (adios_handle, "NX");
	if (!avi){
		p_error("rank %d: Quitting ... (%d) %s\n", rank, adios_errno, adios_errmsg());
		diag = DIAG_ERR;
		goto close_adios;
	}

	// I expect a scalar that will tell me the size of an array
	assert(0 == avi->ndim);
	assert(adios_integer == avi->type);
	NX = *((int*)avi->value);
	// I don't need that variable any more
	adios_free_varinfo(avi);
	assert(NX_DIM == NX);
	avi = NULL;


	// this will define the slice that we want to read; each rank should
	// read its own slice written by a corresponding writer rank
	uint64_t count[1] = { NX };
	uint64_t start[1] = { 0 };
	start[0] = rank*NX;

	sel = adios_selection_boundingbox(1,start, count);
	if( !sel ){
		p_error("rank %d: Quitting ... (%d) %s\n", rank, adios_errno, adios_errmsg());
		diag = DIAG_ERR;
		goto close_adios;
	}

	// make the reference array with reference values I expect to get
	t_ref = calloc(NX, sizeof(double));
	if (gen_1D_array(t_ref, NX, rank) == DIAG_ERR){
		p_error("Generating 1D array. Quitting ...\n");
		diag = DIAG_ERR;
		goto close_adios;
	}

	// allocate the memory for the actual array to be read
	t = calloc(NX, sizeof(double));

	if (adios_schedule_read(adios_handle, sel, "var_1d_array",0,1,t) != 0){
		p_error("rank %d: Quitting ...(%d) %s\n", rank, adios_errno, adios_errmsg());
		diag = DIAG_ERR;
		goto just_clean;
	}

	// not sure if this assumption is correct; difficult to find in the ADIOS sources
	if (adios_perform_reads(adios_handle, 1) != 0){
		p_error("rank %d: Quitting ...(%d) %s\n", rank, adios_errno, adios_errmsg());
		diag = DIAG_ERR;
		goto just_clean;
	}

	sprintf(buf, "Rank %d: var_1d_array: step %d: t: ", rank, step);

	int i = 0;
	for(i=0; i < NX; ++i){
		if( t[i] != t_ref[i] ){
			p_test_failed("%s: rank %d: for t[%d] (expected %.1f, got %.1f)\n", test_result.name, rank,  i, t_ref[i], t[i] );
			test_result.result = TEST_FAILED;
			break;
		}
	}

	if (TEST_PASSED == test_result.result)
		p_test_passed("%s: rank %d\n", test_result.name, rank);

just_clean:
	// clean everything
	adios_selection_delete(sel);
	sel = NULL;
	free(t);
	t = NULL;
	free(t_ref);
	t_ref = NULL;

close_adios:
	CLOSE_ADIOS_READER(adios_handle, adios_opts.method);

	if ((DIAG_OK == diag) && (TEST_PASSED == test_result.result)) {
		return 0;
	} else {
		return 1;
	}
}