void oskar_station_create_child_stations(oskar_Station* station,
        int* status)
{
    int i, type, location;

    /* Check if safe to proceed. */
    if (*status) return;

    /* Check that the memory isn't already allocated. */
    if (station->child)
    {
        *status = OSKAR_ERR_MEMORY_ALLOC_FAILURE;
        return;
    }

    /* Allocate memory for child station array. */
    station->child = (oskar_Station**) malloc(
            station->num_elements * sizeof(oskar_Station*));
    if (!station->child)
    {
        *status = OSKAR_ERR_MEMORY_ALLOC_FAILURE;
        return;
    }

    /* Create and initialise each child station. */
    type = oskar_station_precision(station);
    location = oskar_station_mem_location(station);
    for (i = 0; i < station->num_elements; ++i)
    {
        station->child[i] = oskar_station_create(type, location, 0, status);
    }
}
oskar_Station* oskar_station_create_copy(const oskar_Station* src,
        int location, int* status)
{
    int i = 0;
    oskar_Station* model = 0;

    /* Check if safe to proceed. */
    if (*status) return model;

    /* Create the new model. */
    model = oskar_station_create(oskar_station_precision(src), location,
            oskar_station_num_elements(src), status);

    /* Set meta-data. */
    model->unique_id = src->unique_id;
    model->precision = src->precision;
    model->mem_location = location;

    /* Copy common station parameters. */
    model->station_type = src->station_type;
    model->normalise_final_beam = src->normalise_final_beam;
    model->lon_rad = src->lon_rad;
    model->lat_rad = src->lat_rad;
    model->alt_metres = src->alt_metres;
    model->pm_x_rad = src->pm_x_rad;
    model->pm_y_rad = src->pm_y_rad;
    model->beam_lon_rad = src->beam_lon_rad;
    model->beam_lat_rad = src->beam_lat_rad;
    model->beam_coord_type = src->beam_coord_type;
    oskar_mem_copy(model->noise_freq_hz, src->noise_freq_hz, status);
    oskar_mem_copy(model->noise_rms_jy, src->noise_rms_jy, status);

    /* Copy aperture array data, except num_element_types (done later). */
    model->identical_children = src->identical_children;
    model->num_elements = src->num_elements;
    model->normalise_array_pattern = src->normalise_array_pattern;
    model->enable_array_pattern = src->enable_array_pattern;
    model->common_element_orientation = src->common_element_orientation;
    model->array_is_3d = src->array_is_3d;
    model->apply_element_errors = src->apply_element_errors;
    model->apply_element_weight = src->apply_element_weight;
    model->seed_time_variable_errors = src->seed_time_variable_errors;
    model->num_permitted_beams = src->num_permitted_beams;

    /* Copy Gaussian station beam data. */
    model->gaussian_beam_fwhm_rad = src->gaussian_beam_fwhm_rad;
    model->gaussian_beam_reference_freq_hz = src->gaussian_beam_reference_freq_hz;

    /* Copy memory blocks. */
    oskar_mem_copy(model->element_true_x_enu_metres,
            src->element_true_x_enu_metres, status);
    oskar_mem_copy(model->element_true_y_enu_metres,
            src->element_true_y_enu_metres, status);
    oskar_mem_copy(model->element_true_z_enu_metres,
            src->element_true_z_enu_metres, status);
    oskar_mem_copy(model->element_measured_x_enu_metres,
            src->element_measured_x_enu_metres, status);
    oskar_mem_copy(model->element_measured_y_enu_metres,
            src->element_measured_y_enu_metres, status);
    oskar_mem_copy(model->element_measured_z_enu_metres,
            src->element_measured_z_enu_metres, status);
    oskar_mem_copy(model->element_weight, src->element_weight, status);
    oskar_mem_copy(model->element_gain, src->element_gain, status);
    oskar_mem_copy(model->element_gain_error, src->element_gain_error, status);
    oskar_mem_copy(model->element_phase_offset_rad,
            src->element_phase_offset_rad, status);
    oskar_mem_copy(model->element_phase_error_rad,
            src->element_phase_error_rad, status);
    oskar_mem_copy(model->element_x_alpha_cpu,
            src->element_x_alpha_cpu, status);
    oskar_mem_copy(model->element_x_beta_cpu,
            src->element_x_beta_cpu, status);
    oskar_mem_copy(model->element_x_gamma_cpu,
            src->element_x_gamma_cpu, status);
    oskar_mem_copy(model->element_y_alpha_cpu,
            src->element_y_alpha_cpu, status);
    oskar_mem_copy(model->element_y_beta_cpu,
            src->element_y_beta_cpu, status);
    oskar_mem_copy(model->element_y_gamma_cpu,
            src->element_y_gamma_cpu, status);
    oskar_mem_copy(model->element_types, src->element_types, status);
    oskar_mem_copy(model->element_types_cpu, src->element_types_cpu, status);
    oskar_mem_copy(model->element_mount_types_cpu, src->element_mount_types_cpu, status);
    oskar_mem_copy(model->permitted_beam_az_rad, src->permitted_beam_az_rad, status);
    oskar_mem_copy(model->permitted_beam_el_rad, src->permitted_beam_el_rad, status);

    /* Copy element models, if set. */
    if (oskar_station_has_element(src))
    {
        /* Ensure enough space for element model data. */
        oskar_station_resize_element_types(model, src->num_element_types,
                status);

        /* Copy the element model data. */
        for (i = 0; i < src->num_element_types; ++i)
        {
            oskar_element_copy(model->element[i], src->element[i], status);
        }
    }

    /* Recursively copy child stations. */
    if (oskar_station_has_child(src))
    {
        model->child = malloc(src->num_elements * sizeof(oskar_Station*));
        if (!model->child)
        {
            *status = OSKAR_ERR_MEMORY_ALLOC_FAILURE;
            return model;
        }

        for (i = 0; i < src->num_elements; ++i)
        {
            model->child[i] = oskar_station_create_copy(
                    oskar_station_child_const(src, i), location, status);
        }
    }

    return model;
}
Ejemplo n.º 3
0
int benchmark(int num_elements, int num_directions, OpType op_type,
        int loc, int precision, bool evaluate_2d, int niter, double& time_taken)
{
    int status = 0;

    // Create the timer.
    oskar_Timer *tmr = oskar_timer_create(OSKAR_TIMER_CUDA);

    oskar_Station* station = oskar_station_create(precision, loc,
            num_elements, &status);
    if (status) return status;
    station->array_is_3d = (evaluate_2d) ? OSKAR_FALSE : OSKAR_TRUE;

    oskar_Mem *x, *y, *z, *weights = 0, *beam = 0, *signal = 0;
    x = oskar_mem_create(precision, loc, num_directions, &status);
    y = oskar_mem_create(precision, loc, num_directions, &status);
    z = oskar_mem_create(precision, loc, num_directions, &status);
    if (status) return status;

    if (op_type == O2C)
    {
        int type = precision | OSKAR_COMPLEX;
        beam = oskar_mem_create(type, loc, num_directions, &status);
        weights = oskar_mem_create(type, loc, num_elements, &status);
        if (status) return status;

        oskar_timer_start(tmr);
        for (int i = 0; i < niter; ++i)
        {
            oskar_evaluate_array_pattern(beam, 2.0 * M_PI, station,
                    num_directions, x, y, z, weights, &status);
        }
        time_taken = oskar_timer_elapsed(tmr);
    }
    else if (op_type == C2C || op_type == M2M)
    {
        int type = precision | OSKAR_COMPLEX;
        int num_signals = num_directions * num_elements;

        weights = oskar_mem_create(type, loc, num_elements, &status);
        if (op_type == C2C)
        {
            beam = oskar_mem_create(type, loc, num_directions, &status);
            signal = oskar_mem_create(type, loc, num_signals, &status);
        }
        else
        {
            type |= OSKAR_MATRIX;
            beam = oskar_mem_create(type, loc, num_directions, &status);
            signal = oskar_mem_create(type, loc, num_signals, &status);
        }
        if (status) return status;

        oskar_timer_start(tmr);
        for (int i = 0; i < niter; ++i)
        {
            oskar_evaluate_array_pattern_hierarchical(beam, 2.0 * M_PI, station,
                    num_directions, x, y, z, signal, weights, &status);
        }
        time_taken = oskar_timer_elapsed(tmr);
    }

    // Destroy the timer.
    oskar_timer_free(tmr);

    // Free memory.
    oskar_station_free(station, &status);
    oskar_mem_free(x, &status);
    oskar_mem_free(y, &status);
    oskar_mem_free(z, &status);
    oskar_mem_free(weights, &status);
    oskar_mem_free(beam, &status);
    oskar_mem_free(signal, &status);

    return status;
}