ningshuxia
9 天以前 9eb7f4af097fb41b81fbff725d930cd6ab052c97
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
/*
 ******************************************************************************
 Project:      OWA EPANET
 Version:      2.2
 Module:       test_reent.cpp
 Description:  Tests EPANET toolkit api functions
 Authors:      see AUTHORS
 Copyright:    see AUTHORS
 License:      see LICENSE
 Last Updated: 03/21/2019
 ******************************************************************************
*/
 
#include <boost/thread.hpp>
 
#include <string>
#include <stdio.h>
#include <stdlib.h>
 
#include "epanet2_2.h"
 
#define NUM_THREADS 2
 
using namespace std;
 
void  epanet_thread(long i)
{
    int errorcode = 0;
    EN_Project ph;
 
    string prefix = "example_";
    string suffix = ".inp";
    string input = prefix + to_string(static_cast<long long>(i)) + suffix;
 
    suffix = ".rpt";
    string report = prefix + to_string(static_cast<long long>(i)) + suffix;
 
    suffix = ".out";
    string output = prefix + to_string(static_cast<long long>(i)) + suffix;
 
    printf("Thread #%ld starting EPANET ...\n", i);
 
    EN_createproject(&ph);
    errorcode = EN_runproject(ph, input.c_str(), report.c_str(), output.c_str(), NULL);
    EN_deleteproject(ph);
 
    printf("Thread #%ld EPANET done. Status = %d\n", i, errorcode);
}
 
int main(int argc, char *argv[])
{
    long i;
    boost::thread *threads[NUM_THREADS];
 
    for (i = 0; i < NUM_THREADS; i++) {
        threads[i] = new boost::thread(epanet_thread, i);
        printf("Main: creating thread %ld.\n", i);
    }
 
    for (i = 0; i < NUM_THREADS; i++) {
        threads[i]->join();
        printf("Main: joining thread %ld.\n", i);
        delete threads[i];
    }
 
    printf("Main: program completed. Exiting.\n");
    return(0);
}