PARCEL SYCL v1.2 / API Reference User Guide API Reference Search Download 日本語

7 parcel::vector

A class that holds a vector on the device. Storage is allocated in SYCL USM (Unified Shared Memory) device memory. All host transfer functions (the setValue / getValue family) wait for the transfer to complete before returning.

7.1 Constructor / resize()

Description Allocates a vector of length n on the device. resize() reallocates it with a new length and queue.

Synopsis

template< class parceltype = parcel_double >
class vector;

parcel::vector<parceltype>::vector(size_t n, sycl::queue *q);
void resize(size_t n, sycl::queue *q);

Arguments

Name In/Out Type Description Default
parceltype In (template) PARCEL data type Precision in which the entries are stored parcel_double
n In size_t Number of entries none
q In sycl::queue * Queue of the device on which the vector is placed none

Requirements Not checked. If the device memory cannot be allocated, util_sycl::device_bad_alloc (derived from std::bad_alloc) is thrown (see Handling of Settings and Exceptions).

MPI Local operation.

Notes The allocated storage is initialized to 0. resize() discards the previous contents. The length of a vector passed to a solver is the number of locally owned rows (for the eigenvalue solvers, the length given in the entry for each solver).

Example

parcel::vector<parcel_double> x(n, &q), b(n, &q);

7.2 queue() / size()

Description Return the pointer to the queue and the number of entries.

Synopsis

sycl::queue *queue();
size_t       size();

Return Value The pointer to the sycl::queue used for allocation, and the number of entries.

MPI Local operation.

7.3 setValue()

Description Copies the values of a host array into the vector.

Synopsis

template< class T > void setValue(T *mem);
template< class T > void setValue(std::vector<T> &mem);
void setValue(parcel::scalar val);
void setValue(double *mem_hi, double *mem_lo);
void setValue(std::vector<double> &mem_hi, std::vector<double> &mem_lo);

Arguments

Name In/Out Type Description Default
T In (template) numeric type Type of the host array. Converted to the precision of parceltype none
mem In T * Host array of length size() none
val In parcel::scalar Value set to all entries. A double or a float can be passed (b.setValue(1.0)) none
mem_hi, mem_lo In double * High and low parts of double-double (length size()) none

Requirements Not checked. The arrays must have at least size() entries.

MPI Local operation.

Notes Copying into parcel_doubledouble with setValue(mem) sets the low part to 0. Copying into a type other than double-double with setValue(mem_hi, mem_lo) stores the rounded value of mem_hi + mem_lo.

See Also getValue(), setValue_hi()

Example

x.setValue(x_h.data());

7.4 setValue_hi() / setValue_lo()

Description Copies the values of a host array into only the high / low array of a double-double vector.

Synopsis

void setValue_hi(double *mem_hi);
void setValue_lo(double *mem_lo);

Arguments

Name In/Out Type Description Default
mem_hi / mem_lo In double * Host array of length size() none

Requirements Only for parcel::vector<parcel_doubledouble>. Calling it on any other type causes a compilation error.

MPI Local operation.

7.5 getValue()

Description Copies the values of the vector into a host array.

Synopsis

template< class T > void getValue(T *mem);
template< class T > void getValue(T *mem_hi, T *mem_lo);
void getValue(double *mem_hi, double *mem_lo);

Arguments

Name In/Out Type Description Default
T In (template) numeric type Type of the host array none
mem Out T * Host array of length size() none
mem_hi, mem_lo Out T * High and low parts of double-double (length size()) none

Requirements Not checked. The arrays must have at least size() entries.

MPI Local operation.

Notes Receiving a double-double vector with getValue(mem) yields the sum of the high and low parts rounded to T. Calling getValue(mem_hi, mem_lo) on a type other than double-double stores the values in mem_hi and writes nothing to mem_lo.

Example

x.getValue(x_h.data());

7.6 getValue_hi() / getValue_lo()

Description Copies the high / low array of a double-double vector into a host array.

Synopsis

template< class T > void getValue_hi(T *mem_hi);
template< class T > void getValue_lo(T *mem_lo);
template< class T > void getValue_hi(std::vector<T> &mem_hi);
template< class T > void getValue_lo(std::vector<T> &mem_lo);

Arguments

Name In/Out Type Description Default
mem_hi / mem_lo Out T * Host array of length size() none

Requirements Not checked. For types other than double-double, T must be the same type as the element type (otherwise a compilation error).

MPI Local operation.

Notes For types other than double-double, getValue_hi() is the same as getValue(), and getValue_lo() writes nothing.

7.7 data() / data_hi() / data_lo()

Description Return the pointer to the beginning of the array on the device.

Synopsis

auto *data();
auto *data_hi();
auto *data_lo();

Return Value The pointer to the beginning of the USM device memory. For double-double, data() and data_hi() return the high part and data_lo() the low part, as double *. For types other than double-double, data() and data_hi() point to the same array, and data_lo() is nullptr.

MPI Local operation.

Notes Since this is device memory, it must not be dereferenced directly from the host (use it inside SYCL kernels).