root/orte/test/system/mapper.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /* -*- C -*-
   2  */
   3 
   4 #include <stdio.h>
   5 #include <ctype.h>
   6 
   7 #include "orte/constants.h"
   8 
   9 #include "opal/util/argv.h"
  10 
  11 #include "orte/runtime/runtime.h"
  12 #include "orte/util/proc_info.h"
  13 #include "orte/util/name_fns.h"
  14 #include "orte/runtime/orte_globals.h"
  15 
  16 #define LINE_LENGTH 10000
  17 
  18 int main(int argc, char* argv[])
  19 {
  20     char text[LINE_LENGTH];
  21     char **invals=NULL;
  22     int i, j;
  23 
  24     if (1 < argc) {
  25         if (ORTE_SUCCESS != orte_init(&argc, &argv, ORTE_PROC_NON_MPI)) {
  26             fprintf(stderr, "Failed orte_init\n");
  27             exit(1);
  28         }
  29     }
  30 
  31     memset(text, 0, sizeof(text));
  32     while (fgets(text, sizeof(text), stdin)) {
  33         /* remove trailing newline */
  34         if ('\n' == text[strlen(text)-1]) {
  35             text[strlen(text)-1] = '\0';
  36         }
  37         /* break the line on white space */
  38         for (i=0, j=0; i < LINE_LENGTH && '\0' != text[i]; i++) {
  39             if (isspace(text[i])) {
  40                 if (j < i) {
  41                     text[i] = '\0';
  42                     opal_argv_append_nosize(&invals, &text[j]);
  43                 }
  44                 j = i+1;
  45             }
  46         }
  47         if (i < LINE_LENGTH && j < i+1) {
  48             opal_argv_append_nosize(&invals, &text[j]);
  49         }
  50         if (NULL == invals) {
  51             fprintf(stderr, "stdin complete (text strlen: %lu)\n", strlen(text));
  52             break;
  53         }
  54         for (i=0; NULL != invals[i]; i++) {
  55             fprintf(stdout, "%s\t1\n", invals[i]);
  56         }
  57         if (NULL != invals) {
  58             opal_argv_free(invals);
  59             invals = NULL;
  60         }
  61         memset(text, 0, sizeof(text));
  62     }
  63 
  64     if (1 < argc) {
  65         fprintf(stderr, "%s: FINALIZING\n", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));
  66         fflush(stderr);
  67 
  68         if (ORTE_SUCCESS != orte_finalize()) {
  69             fprintf(stderr, "Failed orte_finalize\n");
  70             exit(1);
  71         }
  72     }
  73 
  74     return 0;
  75 }

/* [<][>][^][v][top][bottom][index][help] */