blob: 9fddd6260de12d7b5f28ef4327a8df1633c1256a [file] [log] [blame]
<html>
<head>
<title>shmem_float_put</title>
</head>
<h2 id="top">shmem_float_put</h2>
<h4>Purpose</h4>
<p>Transfers data to a specified processing element(PE).
</p>
<h4>C syntax</h4>
<pre>
#include &lt;shmem.h&gt;
void shmem_float_put(float *target, const float *source, size_t len, int pe);
</pre>
<h4>Parameters</h4>
<dl>
<dt class="bold">INPUT</dt>
<dd>
</dd>
<dt class="bold ">target</dt>
<dd>Data object to be updated on the remote PE. This data object must be remotely accessible.
</dd>
<dt class="bold ">source</dt>
<dd>Data object containing the data to be copied.
</dd>
<dt class="bold">len</dt>
<dd>Number of elements in the target and source arrays.
</dd>
<dt class="bold">pe</dt>
<dd>Processing element number of the remote PE.
</dd>
</dl>
<h4>Description</h4>
<div class="ledi">
<p>This routine provides a high-performance method for copying a contiguous data object from the local PE to a contiguous data object on a different PE</p>
<p>This routine returns when the data has been copied out of the source array on the local PE, but not necessarily before the data has been delivered to the remote data object. To enforce the ordering/completion of the put routines, the use of shmem_fence, shmem_quiet, shmem_barrier or shmem_barrier_all is needed.</p>
<p>The function shmem_float_put() writes contiguous elements of float type to
the remote PE.</p>
<h4>IBM NOTES</h4>
<div class="ledi">
<dl>
<p>Please refer to Atomicity and Coherency section for atomicity and coherence model in the OpenSHMEM documentation</p>
</dd>
</dl>
<h4>C examples</h4>
<pre>
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;shmem.h&gt;
#define GLOBAL_ARRAY_SIZE 10
#define INT_INIT_VALUE 1234
//can not use #define
const float FLOAT_INIT_VALUE = 1234.123456;
static float gFloatElement = 0;
static float gFloatArray[GLOBAL_ARRAY_SIZE] = {0};
static int gIntElement = 0;
static int gIntArray[GLOBAL_ARRAY_SIZE] = {0};
int main (int argc, char* argv[])
{
int total_tasks = -1;
int my_task = -1;
start_pes(0);
total_tasks = _num_pes();
if (total_tasks <= 0) {
printf("FAILED\n");
exit(1);
} else {
printf("number of pes is %d\n", total_tasks);
}
if (total_tasks < 2 || total_tasks % 2) {
printf("FAILED: The number of pes should be an even number. (at least 2)\n");
exit(1);
}
my_task = _my_pe();
if (my_task < 0){
printf("FAILED\n");
exit(1);
} else {
printf("my pe id is %d\n", my_task);
}
printf("The address of gIntElement is %p\n", &gIntElement);
printf("The address of gIntArray is %p\n", gIntArray);
printf("The address of gFloatElement is %p\n", &gFloatElement);
printf("The address of gFloatArray is %p\n", gFloatArray);
// even tasks put value to odd tasks
if (my_task%2 == 0) {
int tgt_task = my_task + 1;
//for int
gIntElement = INT_INIT_VALUE;
for (int i=0; i&lt;GLOBAL_ARRAY_SIZE; i++) {
gIntArray[i] = INT_INIT_VALUE;
}
shmem_int_p(&gIntElement, gIntElement, tgt_task);
shmem_int_put(gIntArray, gIntArray, GLOBAL_ARRAY_SIZE, tgt_task);
//for float
gFloatElement = FLOAT_INIT_VALUE;
for (int i=0; i&lt;GLOBAL_ARRAY_SIZE; i++) {
gFloatArray[i] = FLOAT_INIT_VALUE;
}
shmem_float_p(&gFloatElement, gFloatElement, tgt_task);
shmem_float_put(gFloatArray, gFloatArray, GLOBAL_ARRAY_SIZE, tgt_task);
}
shmem_barrier_all();
// odd tasks check value
if (my_task%2 == 1) {
//for int
if (gIntElement != INT_INIT_VALUE) {
printf("FAILED: element should be %d instead of %d\n", INT_INIT_VALUE, gIntElement);
exit(1);
}
for (int i=0; i&lt;GLOBAL_ARRAY_SIZE; i++) {
if (gIntArray[i] != INT_INIT_VALUE) {
printf("FAILED, array[%d] should be %d instead of %d\n", i, INT_INIT_VALUE, gIntArray[i]);
}
}
//for float
if (gFloatElement != FLOAT_INIT_VALUE) {
printf("FAILED: element should be %f instead of %f\n", FLOAT_INIT_VALUE, gFloatElement);
exit(1);
}
for (int i=0; i&lt;GLOBAL_ARRAY_SIZE; i++) {
if (gFloatArray[i] != FLOAT_INIT_VALUE) {
printf("FAILED, array[%d] should be %f instead of %f\n", i, FLOAT_INIT_VALUE, gFloatArray[i]);
}
}
}
shmem_barrier_all();
printf("PASSED\n");
return 0;
}
</pre>
<h4>Related information</h4>
<p>Subroutines: shmem_barrier, shmem_put, shmem_fence, shmem_iput, shmem_quiet
</p>
<hr><a href="apiIndex.html">OpenSHMEM API Index</a>
</html>