Rate This Document
Findability
Accuracy
Completeness
Readability

Thread

  • Set the maximum number of threads:

    HmppResult HMPP_SetNumberThreads (int32_t numberThreads);

  • Obtain the current number of threads:

    HmppResult HMPP_GetNumberThreads (int32_t* numberThreads);

  • Obtain the current thread ID:

    HmppResult HMPP_GetThreadIdx (int32_t* threadIdx);

  • Obtain the current multi-thread mode:

    HmppResult HMPP_GetThreadType (HmppThreadType* threadType);

Parameters

Parameter

Description

Value Range

Input/Output

numberThreads

Maximum number of threads (SetNumberThreads)

> 0

Input

numberThreads

Pointer to the number of threads (GetNumberThreads)

The value cannot be NULL.

Output

threadIdx

Pointer to the current thread ID

The value cannot be NULL.

Output

threadType

Pointer to the current thread mode

The value cannot be NULL.

Output

Return Value

  • Success: HMPP_STS_NO_ERR
  • Failure: An error code is returned.

Error Codes

Error Code

Description

HMPP_STS_NULL_PTR_ERR

The input pointer is NULL.

HMPP_STS_SIZE_ERR

The value of len is less than or equal to 0.

Example

#define NUMBER_THREAD_LIM 4
void  Thread_Example()
{
    HmppResult result = HMPP_SetNumberThreads(NUMBER_THREAD_LIM);
    printf("%s\n", HMPP_GetStatusString(result));

    HmppThreadType testThrType;
    result = HMPP_GetThreadType(&testThrType);
    printf("%s\n", HMPP_GetStatusString(result));

    if (testThrType == OMP) {
        printf("thread mode is omp\n");
        #pragma omp parallel for
        for (int32_t i = 0; i < NUMBER_THREAD_LIM; ++i) {
            int32_t testNumThr, testThrIdx;
            HMPP_GetNumberThreads(&testNumThr);
            HMPP_GetThreadIdx(&testThrIdx);
            printf("testNumThr = %d, testThrIdx = %d\n", testNumThr, testThrIdx);
        }
    } else {
        printf("no thread mode\n");
        int32_t testNumThr, testThrIdx;
        HMPP_GetNumberThreads(&testNumThr);
        HMPP_GetThreadIdx(&testThrIdx);
        printf("testNumThr = %d, testThrIdx = %d\n", testNumThr, testThrIdx);
    }
}

Output:

  • Case 1: The multi-thread mode is not enabled for the HMPP.
    No Error
    No Error
    no thread mode
    testNumThr = 1, testThrIdx = 0
  • Case 2: The multi-thread mode is enabled for the HMPP.
    No Error
    No Error
    thread mode is omp
    testNumThr = 4, testThrIdx = 1
    testNumThr = 4, testThrIdx = 3
    testNumThr = 4, testThrIdx = 2
    testNumThr = 4, testThrIdx = 0

1. Only binary packages are released for the HMPP, and the OMP compilation option is not enabled. The multi-thread function is not supported yet.

2. If multi-thread is supported, the printing sequence of threads may be different from the preceding output.