File: mpl_rankmap_str_to_array.unit

package info (click to toggle)
mpich 5.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 251,828 kB
  • sloc: ansic: 1,323,147; cpp: 82,869; f90: 72,420; javascript: 40,763; perl: 28,296; sh: 19,399; python: 16,191; xml: 14,418; makefile: 9,468; fortran: 8,046; java: 4,635; pascal: 352; asm: 324; ruby: 176; awk: 27; lisp: 19; php: 8; sed: 4
file content (60 lines) | stat: -rw-r--r-- 1,321 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
template:
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <string.h>
    #include <stdbool.h>

    #define MAX_SZ 100
    int map[MAX_SZ];

    #define MPL_SUCCESS 0
    #define MPL_ERR_FAIL 1

    [src/mpl/src/mpl_rankmap.c:MPL_rankmap_str_to_array]

    int main(int argc, char **argv)
    {
        int sz = atoi(argv[1]);
        char *mapping = argv[2];

        if (sz > MAX_SZ) {
            printf("sz exceeds limit (%d > %d)\n", sz, MAX_SZ);
            return 1;
        }

        int err = MPL_rankmap_str_to_array(mapping, sz, map);
        
        if (err) {
            printf("err = 0x%x\n", err);
            return 1;
        }

        for (int i = 0; i < sz; i++) {
            printf("%d ", map[i]);
        }
        printf("\n");

        return 0;
    }

TESTS:
    cmd: ./t 4 '(vector,1,2,3,0)'
    expect: 1 2 3 0

    cmd: ./t 12 '(vector,(0,3,4))'
    expect: 0 0 0 0 1 1 1 1 2 2 2 2

    cmd: ./t 12 '(vector,[(0,3,1)]x4)'
    expect: 0 1 2 0 1 2 0 1 2 0 1 2

    cmd: ./t 12 '(vector,[(0,3,1)]x3,(0,3,1))'
    expect: 0 1 2 0 1 2 0 1 2 0 1 2

    cmd: ./t 12 '(vector,[(0,2,1),2]x3,(0,3,1))'
    expect: 0 1 2 0 1 2 0 1 2 0 1 2

    # legacy with default repeats from node 0

    cmd: ./t 12 '(vector,(1,3,1),(0,4,1))'
    expect: 1 2 3 0 1 2 3 0 1 2 3 0