LAPI_Setcntr 子例程
用途
用于将计数器设置为指定的值。
库
可用性库 (liblapi_r.a)
C 语法
#include <lapi.h>
int LAPI_Setcntr(hndl, cntr, val)
lapi_handle_t hndl;
lapi_cntr_t *cntr;
int val;FORTRAN 语法
include 'lapif.h'
LAPI_SETCNTR(hndl, cntr, val, ierror)
INTEGER hndl
TYPE (LAPI_CNTR_T) :: cntr
INTEGER val
INTEGER ierror描述
Type of call: 本地计数器操作
此子例程将 cntr 设置为 val指定的值。 由于无法使 LAPI_Getcntr/LAPI_Setcntr 序列成为原子序列,因此仅当您知道不会有任何竞争操作时,才应使用 LAPI_Setcntr 。
参数
- INPUT
- hndl
- 指定 LAPI 句柄。
- 值
- 指定需要将计数器设置为的值。
- 输入/输出
- cntr
- 指定要设置的计数器的地址 (以 C 为格式) 或计数器结构 (以 FORTRAN 为格式)。 此参数的值不能为 NULL (在 C 中) 或 LAPI_ADDR_NULL (在 FORTRAN 中)。
- 输出
- ierror
- 指定 FORTRAN 返回码。 这始终是最后一个参数。
限制
对于共享内存通信和数据传输,或者对于任务发送到自身的消息, 不会 报告 LAPI 统计信息。
C 示例
要初始化计数器以在通信 API 调用中使用:
{
lapi_cntr_t my_tgt_cntr, *tgt_cntr_array;
int initial_value, expected_value, current_value;
lapi_handle_t hndl;
.
.
.
/*
* Note: the code below is executed on all tasks
*/
/* initialize, allocate and create structures */
initial_value = 0;
expected_value = 1;
/* set the cntr to zero */
LAPI_Setcntr(hndl, &my_tgt_cntr, initial_value);
/* set other counters */
.
.
.
/* exchange counter addresses, LAPI_Address_init synchronizes */
LAPI_Address_init(hndl, &my_tgt_cntr, tgt_cntr_array);
/* more address exchanges */
.
.
.
/* Communication calls using my_tgt_cntr */
LAPI_Put(....., tgt_cntr_array[tgt], ....);
.
.
.
/* Wait for counter to reach value */
for (;;) {
LAPI_Getcntr(hndl, &my_tgt_cntr, ¤t_value);
if (current_value >= expected_value) {
break; /* out of infinite loop */
} else {
LAPI_Probe(hndl);
}
}
.
.
.
/* Quiesce/synchronize to ensure communication using our counter is done */
LAPI_Gfence(hndl);
/* Reset the counter */
LAPI_Setcntr(hndl, &my_tgt_cntr, initial_value);
/*
* Synchronize again so that no other communication using the counter can
* begin from any other task until we're all finished resetting the counter.
*/
LAPI_Gfence(hndl);
/* More communication calls */
.
.
.
}返回值
- 成功 (LAPI_SUCCESS)
- 指示函数调用已成功完成。
- LAPI_ERR_CNTR_NULL
- 指示传入的 cntr 值为 NULL (在 C 中) 或 LAPI_ADDR_NULL (在 FORTRAN 中)。
- LAPI_ERR_HNDL_INVALID
- 指示传入的 hndl 无效 (未初始化或处于终止状态)。
位置
- /usr/lib/liblapi_r.a