Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ahayashi opened this issue Oct 25, 2024 · 0 comments
Open

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

ahayashi opened this issue Oct 25, 2024 · 0 comments
Milestone

Comments

@ahayashi
Copy link

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

@jdinan jdinan added this to the OpenSHMEM 1.7 milestone Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants