Dosyalar
rocm-systems/tests/sos_tests/put_nbi.cpp
T

96 satır
2.6 KiB
C++
Ham Normal Görünüm Geçmiş

2024-07-01 09:57:08 -05:00
/*
* Copyright (c) 2016 Intel COrporation. All rights reserved.
* This software is available to you under the BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modfiication, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/* Non-Blocking Put Test
* Tom St. John <tom.st.john@intel.com>
* January, 2016
*
* PE 0 uses non-blocking put to write a message followed by a
* notification flag to every remote PE,
*/
#include <stdio.h>
#include <string.h>
2024-11-25 14:12:15 -06:00
#include <rocshmem/rocshmem.hpp>
2024-07-01 09:57:08 -05:00
using namespace rocshmem;
int main(int argc, char *argv[]) {
long source[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
long *target;
int *flag;
int i, num_pes;
int failed = 0;
2024-11-25 14:12:15 -06:00
rocshmem_init();
2024-07-01 09:57:08 -05:00
2024-11-25 14:12:15 -06:00
target = (long *)rocshmem_malloc(sizeof(long) * 10);
flag = (int *)rocshmem_malloc(sizeof(int));
2024-07-01 09:57:08 -05:00
if (!flag) {
fprintf(stderr, "ERR - null flag pointer\n");
2024-11-25 14:12:15 -06:00
rocshmem_global_exit(1);
2024-07-01 09:57:08 -05:00
}
*flag = 0;
2024-11-25 14:12:15 -06:00
num_pes = rocshmem_n_pes();
2024-07-01 09:57:08 -05:00
if (target) {
memset(target, 0, sizeof(long) * 10);
} else {
fprintf(stderr, "ERR - null target pointer\n");
2024-11-25 14:12:15 -06:00
rocshmem_global_exit(1);
2024-07-01 09:57:08 -05:00
}
2024-11-25 14:12:15 -06:00
rocshmem_barrier_all();
2024-07-01 09:57:08 -05:00
2024-11-25 14:12:15 -06:00
if (rocshmem_my_pe() == 0) {
2024-07-01 09:57:08 -05:00
for (i = 0; i < num_pes; i++) {
2024-11-25 14:12:15 -06:00
rocshmem_long_put_nbi(target, source, 10, i);
rocshmem_fence();
rocshmem_int64_atomic_inc((int64_t *)flag, i);
2024-07-01 09:57:08 -05:00
}
}
2024-11-25 14:12:15 -06:00
rocshmem_int_wait_until(flag, ROCSHMEM_CMP_EQ, 1);
2024-07-01 09:57:08 -05:00
for (i = 0; i < 10; i++) {
if (target[i] != source[i]) {
fprintf(stderr, "[%d] target[%d] = %ld, expected %ld\n",
2024-11-25 14:12:15 -06:00
rocshmem_my_pe(), i, target[i], source[i]);
2024-07-01 09:57:08 -05:00
failed = 1;
}
}
2024-11-25 14:12:15 -06:00
rocshmem_free(target);
rocshmem_free(flag);
2024-07-01 09:57:08 -05:00
2024-11-25 14:12:15 -06:00
rocshmem_finalize();
2024-07-01 09:57:08 -05:00
return failed;
}