File: XdmfExampleConnectTest2.py

package info (click to toggle)
xdmf 3.0%2Bgit20160803-3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 35,388 kB
  • ctags: 36,627
  • sloc: ansic: 265,382; cpp: 162,889; python: 10,976; f90: 1,378; yacc: 687; fortran: 464; xml: 200; java: 187; lex: 125; makefile: 82; sh: 28
file content (166 lines) | stat: -rw-r--r-- 5,860 bytes parent folder | download | duplicates (6)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
from Xdmf import *
from mpi4py.MPI import *

if __name__ == "__main__":
        #//initDSMWriterConnectRequired begin

        dsmSize = 64
        comm = COMM_WORLD

        id = comm.Get_rank()
        size = comm.Get_size()

        newPath = "dsm"
        newSetPath = "Data"

        # Initializing objects

        testComm = XdmfDSMCommMPI()
        testComm.DupComm(comm)
        testComm.Init()
        testBuffer = XdmfDSMBuffer()
        testBuffer.SetIsServer(False)
        testBuffer.SetComm(testComm)
        testBuffer.SetIsConnected(True)

        exampleWriter = XdmfHDF5WriterDSM.New(newPath, comm);

        exampleWriter.getServerBuffer().GetComm().ReadDsmPortName();

        exampleWriter.getServerBuffer().Connect();

        #//initDSMWriterConnectRequired end

        #//notify begin

        notify = 0

        if size > 1: 
          if id == 0:
            notify = exampleWriter.waitOn(newPath, "notify")
          elif id == size - 1:
            # The user will want to ensure that the wait command is called first
            exampleWriter.waitRelease(newPath, "notify", 3)

        #//notify end

        #//buffernotify begin

        notify = 0

        if size > 1:
          if id == 0:
            notify = exampleWriter.getServerBuffer().WaitOn(newPath, "notify")
          elif id == size - 1:
            # The user will want to ensure that the wait command is called first
            exampleWriter.getServerBuffer().WaitRelease(newPath, "notify", 3)

        #//buffernotify end

        readStartVector = UInt32Vector()
        readStrideVector = UInt32Vector()
        readCountVector = UInt32Vector()
        readDataSizeVector = UInt32Vector()

        readStartVector.push_back(5*id)
        readStrideVector.push_back(1)
        readCountVector.push_back(5)
        readDataSizeVector.push_back(5*size)

        readArray = XdmfArray.New()

        readArray.initializeAsInt32(0)
        readArray.reserve(5)

        readController = XdmfHDF5ControllerDSM.New(
                newPath,
                newSetPath,
                XdmfArrayType.Int32(),
                readStartVector,
                readStrideVector,
                readCountVector,
                readDataSizeVector,
                exampleWriter.getServerBuffer());

        writeStartVector = UInt32Vector();
        writeStrideVector = UInt32Vector();
        writeCountVector = UInt32Vector();
        writeDataSizeVector = UInt32Vector();

        writeStartVector.push_back(id*5);
        writeStrideVector.push_back(1);
        writeCountVector.push_back(5);
        writeDataSizeVector.push_back(5*size);

        writeController = XdmfHDF5ControllerDSM.New(
                newPath,
                newSetPath,
                XdmfArrayType.Int32(),
                writeStartVector,
                writeStrideVector,
                writeCountVector,
                writeDataSizeVector,
                exampleWriter.getServerBuffer());

        exampleWriter.setMode(XdmfHeavyDataWriter.Hyperslab);

        # Done initialization

        readController.getServerBuffer().GetComm().GetIntraComm().Barrier()

        loopamount = 4

        print str(range(0, loopamount)) + "'s type = " + str(type(range(0, loopamount)))

        for numloops in range(0, loopamount):
                if id == 0:
                        receiveData = 0
                        readController.getServerBuffer().ReceiveAcknowledgment(readController.getServerBuffer().GetComm().GetInterId() - 1, receiveData, XDMF_DSM_EXCHANGE_TAG, XDMF_DSM_INTER_COMM)

                readController.getServerBuffer().GetComm().GetIntraComm().Barrier()

                if readArray.getNumberHeavyDataControllers() > 0:
                        readArray.removeHeavyDataController(0)
                readArray.insert(readController)
                readArray.read()

                for i in range(0, size):
                        readController.getServerBuffer().GetComm().GetIntraComm().Barrier()
                        if i == id:
                                outputstream = " "
                                outputstream = outputstream + "Array on core " + str(exampleWriter.getServerBuffer().GetComm().GetInterId()) + " contains:\n"
                                for j in range(0, readArray.getSize()):
                                        tempVal = readArray.getValueAsInt32(j)
                                        tempVal = tempVal * 3
                                        readArray.insertAsInt32(j, [tempVal])
                                        outputstream = outputstream + "[" + str(j) + "]" + str(readArray.getValueAsInt32(j))+ "\n"
                                print outputstream

                readController.getServerBuffer().GetComm().GetIntraComm().Barrier()
                if id == 0:
                        print "\n\n"

                readArray.removeHeavyDataController(0)
                readArray.insert(writeController)

                readArray.accept(exampleWriter)

                if id == 0:
                        receiveData = 0
                        readController.getServerBuffer().SendAcknowledgment(readController.getServerBuffer().GetComm().GetInterId() - 1, receiveData, XDMF_DSM_EXCHANGE_TAG, XDMF_DSM_INTER_COMM)


        # This last acknowledgment is to end the loop.

        if id == 0:
                receiveData = 0;
                readController.getServerBuffer().ReceiveAcknowledgment(readController.getServerBuffer().GetComm().GetInterId() - 1, receiveData, XDMF_DSM_EXCHANGE_TAG, XDMF_DSM_INTER_COMM)

        readController.getServerBuffer().GetComm().GetIntraComm().Barrier()

        if id == 0:
                readController.stopDSM()

        readController.getServerBuffer().GetComm().GetInterComm().Barrier()

        readController.getServerManager().Disconnect()