File: mpl_rankmap_array_to_str.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 (62 lines) | stat: -rw-r--r-- 1,357 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
61
62
template:
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <string.h>
    #include <stdbool.h>
    #include <assert.h>

    #define MAX_SZ 100
    int map[MAX_SZ];

    #define MPL_SUCCESS 0
    #define MPL_ERR_FAIL 1
    #define MPL_malloc(sz,t) malloc(sz)
    #define MPL_realloc(p,sz,t) realloc(p,sz)
    #define MPL_free free

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

    int main(int argc, char **argv)
    {
        int sz = argc - 1;
        if (sz > MAX_SZ) {
            printf("sz exceeds limit (%d > %d)\n", sz, MAX_SZ);
            return 1;
        }
        for (int i = 0; i < sz; i++) {
            map[i] = atoi(argv[1 + i]);
        }

        char *str;
        int err = MPL_rankmap_array_to_str(map, sz, &str);
        
        if (err) {
            printf("err = 0x%x\n", err);
            return 1;
        }
        if (str == NULL) {
            printf("str is NULL\n");
            return 1;
        }

        printf("%s\n", str);

        return 0;
    }

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

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

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

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

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