File: mapper.c

package info (click to toggle)
openmpi 4.1.0-10
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 126,560 kB
  • sloc: ansic: 685,465; makefile: 42,952; f90: 19,220; sh: 7,002; java: 6,360; perl: 3,524; cpp: 2,227; python: 1,350; lex: 989; fortran: 61; tcl: 12
file content (75 lines) | stat: -rw-r--r-- 1,908 bytes parent folder | download | duplicates (4)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
/* -*- C -*-
 */

#include <stdio.h>
#include <ctype.h>

#include "orte/constants.h"

#include "opal/util/argv.h"

#include "orte/runtime/runtime.h"
#include "orte/util/proc_info.h"
#include "orte/util/name_fns.h"
#include "orte/runtime/orte_globals.h"

#define LINE_LENGTH 10000

int main(int argc, char* argv[])
{
    char text[LINE_LENGTH];
    char **invals=NULL;
    int i, j;

    if (1 < argc) {
        if (ORTE_SUCCESS != orte_init(&argc, &argv, ORTE_PROC_NON_MPI)) {
            fprintf(stderr, "Failed orte_init\n");
            exit(1);
        }
    }

    memset(text, 0, sizeof(text));
    while (fgets(text, sizeof(text), stdin)) {
        /* remove trailing newline */
        if ('\n' == text[strlen(text)-1]) {
            text[strlen(text)-1] = '\0';
        }
        /* break the line on white space */
        for (i=0, j=0; i < LINE_LENGTH && '\0' != text[i]; i++) {
            if (isspace(text[i])) {
                if (j < i) {
                    text[i] = '\0';
                    opal_argv_append_nosize(&invals, &text[j]);
                }
                j = i+1;
            }
        }
        if (i < LINE_LENGTH && j < i+1) {
            opal_argv_append_nosize(&invals, &text[j]);
        }
        if (NULL == invals) {
            fprintf(stderr, "stdin complete (text strlen: %lu)\n", strlen(text));
            break;
        }
        for (i=0; NULL != invals[i]; i++) {
            fprintf(stdout, "%s\t1\n", invals[i]);
        }
        if (NULL != invals) {
            opal_argv_free(invals);
            invals = NULL;
        }
        memset(text, 0, sizeof(text));
    }

    if (1 < argc) {
        fprintf(stderr, "%s: FINALIZING\n", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));
        fflush(stderr);

        if (ORTE_SUCCESS != orte_finalize()) {
            fprintf(stderr, "Failed orte_finalize\n");
            exit(1);
        }
    }

    return 0;
}