openshmem-org / specification

OpenSHMEM Application Programming Interface
http://www.openshmem.org
51 stars 41 forks source link

Adding code examples for `shmem_ibput`, `shmem_iget`, and `shmem_ibget` #556

Open ahayashi opened 3 weeks ago

ahayashi commented 3 weeks ago

Problem Statement

The newly added functions shmem_ibput and shmem_ibget currently do not include code examples. shmem_iget does not have an example either. It would be beneficial for the user if we could include code examples.

Proposed Changes

If it's not too late, we'd suggest adding the following code examples (assuming these are correct):

shmem_ibput: PE0 transfers 5 blocks (nblocks=5), where each block has a size of 2 (bsize=2). It uses a source stride of 2 (sst=2) and a destination stride of 2 (dst=2) to send the data to PE1. This essentially copies all the elements from the source on PE0 to the dest on PE1.

#include <shmem.h>
#include <stdio.h>

int main(void) {
    short source[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    static short dest[10];
    shmem_init();
    int mype = shmem_my_pe();
    shmem_ibput(dest, source, 2, 2, 2, 5, 1);
    shmem_barrier_all();
    if (mype == 1) {
        printf("Received data on PE 1: %hd, %hd, %hd, %hd, %hd, %hd, %hd, %hd, %hd, %hd\n",
               dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7], dest[8], dest[9]);
    }
    shmem_finalize();
    return 0;
}

shmem_iget: Each PE retrieves PE0's source array using a source stride of 2 (sst=2), placing the values into the destination array (dest) with a destination stride of 1 (dst=1). This results in copying source[0], source[2], ..., and source[8] into the first half of the destination array.

#include <shmem.h>
#include <stdio.h>

int main(void) {
    static short source[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    short dest[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    shmem_init();
    int mype = shmem_my_pe();
    shmem_iget(dest, source, 1, 2, 5, 0);
    shmem_barrier_all();
    if (mype == 1) {
        printf("Received data on PE 1: %hd, %hd, %hd, %hd, %hd\n",
                dest[0], dest[1], dest[2], dest[3], dest[4]);
   }
   shmem_finalize();
   return 0;
}

shmem_ibget: Each PE retrieves 5 blocks (nblocks=5) of PE0's source array, where each block has a size of 2 (bsize=2). It uses a source stride of 2 (sst=2) and a destination stride of 2 (dst=2). This essentially copies all the elements from the source on PE0 to the dest on each PE.

#include <shmem.h>
#include <stdio.h>

int main(void) {
    static short source[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    short dest[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    shmem_init();
    int mype = shmem_my_pe();
    shmem_ibget(dest, source, 2, 2, 2, 5, 0);
    shmem_barrier_all();
    if (mype == 1) {
        printf("Received data on PE 1: %hd, %hd, %hd, %hd, %hd, %hd, %hd, %hd, %hd, %hd\n",
               dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7], dest[8], dest[9]);
   }
   shmem_finalize();
   return 0;
}

Credit: @youssefelmougy

Impact on Implementations

N/A

Impact on Users

N/A

References and Pull Requests

554