Project

General

Profile

Statistics
| Branch: | Revision:

root / src / sim / parsim / parsimutil.cc @ 81ad8b66

History | View | Annotate | Download (1.58 KB)

1 01873262 Georg Kunz
//=========================================================================
2
//  PARSIMUTIL.CC - part of
3
//
4
//                  OMNeT++/OMNEST
5
//           Discrete System Simulation in C++
6
//
7
//  Author: Andras Varga, 2003
8
//          Dept. of Electrical and Computer Systems Engineering,
9
//          Monash University, Melbourne, Australia
10
//
11
//=========================================================================
12
13
/*--------------------------------------------------------------*
14
  Copyright (C) 2003-2008 Andras Varga
15
  Copyright (C) 2006-2008 OpenSim Ltd.
16

17
  This file is distributed WITHOUT ANY WARRANTY. See the file
18
  `license' for details on this and other legal matters.
19
*--------------------------------------------------------------*/
20
21
#include <string.h>
22
#include "cenvir.h"
23
#include "parsimutil.h"
24
#include "cexception.h"
25
26
USING_NAMESPACE
27
28
29
void getProcIdFromCommandLineArgs(int& myProcId, int& numPartitions, const char *caller)
30
{
31
    int argc = ev.getArgCount();
32
    char **argv = ev.getArgVector();
33
    int i;
34
    for (i=1; i<argc; i++)
35
        if (argv[i][0]=='-' && argv[i][1]=='p')
36
            break;
37
    if (i==argc)
38
        throw cRuntimeError("%s: missing -p<procId>,<numPartitions> switch on the command line", caller);
39
40
    char *parg = argv[i];
41
    myProcId = atoi(parg+2);
42
    char *s = parg;
43
    while (*s!=',' && *s) s++;
44
    numPartitions = (*s) ? atoi(s+1) : 0;
45
    if (myProcId<0 || numPartitions<=0 || myProcId>=numPartitions)
46
        throw cRuntimeError("%s: invalid switch '%s' -- should have the format -p<procId>,<numPartitions>",
47
                                caller, parg);
48
}