File: XdmfExampleDSMNoThread.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 (705 lines) | stat: -rw-r--r-- 21,764 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
from Xdmf import *
from mpi4py.MPI import *

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

        #The total size of the DSM being created
        dsmSize = 64
        comm = COMM_WORLD

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

        #//initMPI end

        testArray = XdmfArray.New()
        testArray.initializeAsInt32(0)

        for i in range(1,5):
                testArray.pushBackAsInt32(i*(id+1))

        #//initwritevector begin

        newPath = "dsm"
        newSetPath = "data"

        numServersCores = 4

        writeStartVector = UInt32Vector()
        writeStartVector.push_back(id*4)
        #writeStartVector.push_back(id);
        writeStrideVector = UInt32Vector()
        writeStrideVector.push_back(1)
        #writeStrideVector.push_back(size-3);
        writeCountVector = UInt32Vector()
        writeCountVector.push_back(4)
        writeDataSizeVector = UInt32Vector()
        writeDataSizeVector.push_back(4*(size-numServersCores))

        #//initwritevector end

        #//splitcomm begin

        ServerIds = []

        for i in range(size-numServersCores, size):
                ServerIds.append(i)

        workers = comm.Get_group().Excl(ServerIds)

        workerComm = comm.Create(workers)

        #//splitcomm end

        #//initwritergenerate begin

        exampleWriter = XdmfHDF5WriterDSM.New(newPath, comm, dsmSize/numServersCores, size-numServersCores, size-1)

        #//initwritergenerate end

        '''
        #//initwriterpagedgenerate begin

        exampleWriter = XdmfHDF5WriterDSM.New(newPath, comm, dsmSize/numServersCores, 1024, 1.0, size-numServersCores, size-1)

        #//initwriterpagedgenerate end
        '''

        '''
        #//initcontrollergenerate begin

        exampleController = XdmfHDF5ControllerDSM.New(
                newPath,
                newSetPath,
                XdmfArrayType.Int32(),
                writeStartVector,
                writeStrideVector,
                writeCountVector,
                writeDataSizeVector,
                comm,
                dsmSize/numServersCores,
                size-numServersCores,
                size-1)

        #//initcontrollergenerate end
        '''

        '''
        #//initcontrollerpagedgenerate begin


        exampleController = XdmfHDF5ControllerDSM.New(
                newPath,
                newSetPath,
                XdmfArrayType.Int32(),
                writeStartVector,
                writeStrideVector,
                writeCountVector,
                writeDataSizeVector,
                comm,
                dsmSize/numServersCores,
                1024,
                1.0,
                size-numServersCores,
                size-1)

        #//initcontrollerpagedgenerate end
        '''

        # Split out sub-comm for the worker cores
        # Server cores will not progress to this point until after the servers are done running

        #//startworksection begin

        if (id < size - numServersCores):

                #//startworksection end

                # This section is to demonstrate the functionality of the XdmfDSM classes

                #//setServerModewriter begin

                exampleWriter.setServerMode(True)

                #//setServerModewriter end

                #//getServerModewriter begin

                exampleServerMode = exampleWriter.getServerMode()

                #//getServerModewriter end

                #//getWorkerCommwriter begin

                exampleWorkerComm = exampleWriter.getWorkerComm()

                #//getWorkerCommwriter end

                #//setWorkerCommwriter begin

                exampleWriter.setWorkerComm(exampleWorkerComm)

                #//setWorkerCommwriter end

                '''
                #//getWorkerCommcontroller begin

                exampleWorkerComm = exampleController.getWorkerComm()

                #//getWorkerCommcontroller end

                #//setWorkerCommcontroller begin

                exampleController.setWorkerComm(exampleWorkerComm)

                #//setWorkerCommcontroller end

                #//setServerModecontroller begin

                exampleController.setServerMode(True)

                #//setServerModecontroller end

                #//getServerModecontroller begin

                exampleControllerServerMode = exampleController.getServerMode()

                #//getServerModecontroller end
                '''

                #//initcontrollerfrombuffer begin

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

                #//initcontrollerfrombuffer end

                #//initwriterfrombuffer begin

                exampleWriter2 = XdmfHDF5WriterDSM.New(newPath, exampleWriter.getServerBuffer());

                #//initwriterfrombuffer end

                writeController.setServerMode(True)
                exampleControllerServerMode = writeController.getServerMode()

                #//getServerBufferwriter begin

                exampleBuffer = exampleWriter.getServerBuffer()

                #//getServerBufferwriter end

                #//GetlocalBufferSizeMBytes begin

                exampleBufferSize = exampleBuffer.GetLocalBufferSizeMBytes()

                #//GetLocalBufferSizeMBytes end

                #//SetLocalBufferSizeMBytes begin

                exampleBuffer.SetLocalBufferSizeMBytes(exampleBufferSize)

                #//SetLocalBufferSizeMBytes end

                #//GetInterCommType begin

                exampleCommType = exampleBuffer.GetInterCommType()

                #//GetInterCommType end

                #//SetinterCommType begin

                exampleBuffer.SetInterCommType(XDMF_DSM_COMM_MPI)

                #//SetInterCommType end

                '''
                #//Create begin

                exampleBuffer.Create(size - numServerCores, size - 1)

                #//Create end
                '''

                #//setBufferwriter begin

                exampleWriter.setBuffer(exampleBuffer)

                #//setBufferwriter end

                '''
                #//getServerBuffercontroller begin

                exampleBuffer = exampleController.getServerBuffer()

                #//getServerBuffercontroller end

                #//setBuffercontroller begin

                exampleController.setBuffer(exampleBuffer)

                #//setBuffercontroller end
                '''

                #//GetIsConnectedbuffer begin

                exampleIsConnected = exampleBuffer.GetIsConnected()

                #//GetIsConnectedbuffer end

                #//SetIsConnectedbuffer begin

                exampleBuffer.SetIsConnected(exampleIsConnected)

                #//SetIsConnectedbuffer end

                #//GetDataPointer begin

                exampleDataPointer = exampleBuffer.GetDataPointer()

                #//GetDataPointer end

                #//GetDsmTypebuffer begin

                exampleDSMType = exampleBuffer.GetDsmType()

                #//GetDsmTypebuffer end

                #//SetDsmTypebuffer begin

                exampleBuffer.SetDsmType(XDMF_DSM_TYPE_UNIFORM)

                #//SetDsmTypebuffer end

                #//GetIsServerbuffer begin

                exampleBufferIsServer = exampleBuffer.GetIsServer()

                #//GetIsServerbuffer end

                #//SetIsServerbuffer begin

                exampleBuffer.SetIsServer(exampleIsServer)

                #//SetIsServerbuffer end

                #//GetStartAddress begin

                exampleBufferStart = exampleBuffer.GetStartAddress()

                #//GetStartAddress end

                #//GetEndAddress begin

                exampleBufferEnd = exampleBuffer.GetEndAddress()

                #//GetEndAddress end

                #//GetStartServerId begin

                exampleServerStart = exampleBuffer.GetStartServerId()

                #//GetStartServerId end

                #//GetEndServerid begin

                exampleServerEnd = exampleBuffer.GetEndServerId()

                #//GetEndServerId end

                #//GetLength begin

                exampleBufferLength = exampleBuffer.GetLength()

                #//GetLength end

                #//UpdateLength begin

                exampleBuffer.UpdateLength(exampleBufferLength)

                #//UpdateLength end

                #//GetTotalLength begin

                exampleTotalBufferLength = exampleBuffer.GetTotalLength()

                #//GetTotalLength end

                #//GetBlockLengthbuffer begin

                exampleBufferBlockLength = exampleBuffer.GetBlockLength()

                #//GetBlockLengthbuffer end

                #//SetBlockLengthbuffer begin

                exampleBuffer.SetBlockLength(exampleBufferBlockLength)

                #//SetBlockLengthbuffer end

                '''
                #//ConfigureUniform begin

                exampleBuffer.ConfigureUniform(exampleBuffer.GetComm(), dsmSize/numServersCores, size - numServersCores, size - 1)

                #//ConfigureUniform end
                '''
                sendingCore = -1

                #//SendCommandHeader begin

                if (id == sendingCore):
                        exampleBuffer.SendCommandHeader(XDMF_DSM_OPCODE_DONE, 1, 0, 0, XDMF_DSM_INTER_COMM)

                #//SendCommandHeader end

                #//SendData begin

                if (id == sendingCore):
                        sentData = "datastring"
                        exampleBuffer.SendData(1, sentData, 0, XDMF_DSM_PUT_DATA_TAG, 0, XDMF_DSM_INTER_COMM)

                #//SendData end

                #//SendAcknowledgment begin

                if (id == 1):
                        sentData = 1
                        exampleBuffer.SendAcknowledgment(0, sentData, XDMF_DSM_PUT_DATA_TAG, XDMF_DSM_INTER_COMM)

                #//SendAcknowledgment end

                #//ReceiveAcknowledgement begin

                if (id == 0):
                        recvData = 0
                        exampleBuffer.ReceiveAcknowledgment(1, recvData, XDMF_DSM_PUT_DATA_TAG, XDMF_DSM_INTER_COMM)

                #//ReceiveAcknowledgement end



                ServerIds = []

                for i in range(0, (size - numServersCores) / 2):
                        ServerIds.append(i)

                readingCores = workerComm.Get_group().Excl(ServerIds)

                readComm = workerComm.Create(readingCores)

                writingCores = workerComm.Get_group().Incl(ServerIds)

                writeComm = workerComm.Create(writingCores)

                exampleBuffer.GetComm().DupComm(workerComm)

                #//BufferService begin

                if (id == 0):
                        serviceOut = exampleBuffer.BufferService()

                if (id == 1):
                        exampleBuffer.SendCommandHeader(XDMF_DSM_OPCODE_DONE, 0, 0, 0, XDMF_DSM_INTER_COMM)

                #//BufferService end

                #//BufferServiceLoop begin

                if (id == 0):
                        exampleBuffer.BufferServiceLoop()

                if (id == 1):
                        exampleBuffer.SendCommandHeader(XDMF_DSM_OPCODE_DONE, 0, 0, 0, XDMF_DSM_INTER_COMM)

                #//BufferServiceLoop end

                #//AddressToId begin

                correspondingId = exampleBuffer.AddressToId(500)

                #//AddressToId end

                #//GetComm begin

                exampleDSMComm = exampleBuffer.GetComm()

                #//GetComm end

                #//SetComm begin

                exampleBuffer.SetComm(exampleDSMComm)

                #//SetComm end

                #//GetId begin

                exampleIntraID = exampleDSMComm.GetId()

                #//GetId end

                #//GetIntraSize begin

                exampleIntraSize = exampleDSMComm.GetIntraSize()

                #//GetIntraSize end

                #//GetInterId begin

                exampleInterID = exampleDSMComm.GetInterId()

                #//GetInterId end

                #//GetInterSize begin

                exampleInterSize = exampleDSMComm.GetInterSize()

                #//GetInterSize end

                #//GetInterCommType begin

                exampleInterCommType = exampleDSMComm.GetInterCommType()

                #//GetInterCommType end

                #//initcomm begin

                exampleDSMComm.Init()

                #//initcomm end

                #//GetIntraComm begin

                exampleIntraComm = exampleDSMComm.GetIntraComm()

                #//GetIntraComm end

                #//DupComm begin

                exampleDSMComm.DupComm(exampleIntraComm.Dup())

                #//DupComm end

                #//DSMBarrier begin

                exampleDSMComm.Barrier(XDMF_DSM_INTRA_COMM)

                #//DSMBarrier end


                print type(exampleDSMComm.GetDsmPortName())
                testName = "test"
                exampleDSMComm.SetDsmPortName(testName)
                print exampleDSMComm.GetDsmPortName()

                '''

                connectingGroup = True
                if (id < 5):
                        connectingGroup = True;
                else:
                        connectingGroup = False;

                portString = ""

                if (!connectingGroup):
                        exampleDSMComm.OpenPort()
                        portString = exampleDSMComm.GetDsmPortName()
                        // Send the port string to the connecting group
                        exampleDSMComm.Accept()
                        // When done with connection
                        exampleDSMComm.ClosePort()

                if (connectingGroup):
                        // Recieve string from Master group
                        exampleDSMComm.SetDsmPortName(portString)
                        exampleDSMComm.Connect()
                        // When done with connection
                        exampleDSMComm.Disconnect()

                if (connectingGroup):
                        // Recieve string from Master group
                        exampleDSMComm.SetDsmPortName(portString);
                        exampleManager.Connect();
                        // When done with connection
                        exampleManager.Disconnect();

                '''

                # This is the end of the Demonstration

                exampleWriter.setMode(XdmfHeavyDataWriter.Hyperslab)

                testArray.insert(writeController)

                for i in range(0, size-numServersCores):
                        workerComm.Barrier()
                        if (i == id):
                                print "Core # " + str(id)
                                print "Controller stats" 
                                print "datasetpath = " + testArray.getHeavyDataController(0).getDataSetPath() 
                                print "filepath = " + testArray.getHeavyDataController(0).getFilePath()
                                outputVector = testArray.getHeavyDataController(0).getDataspaceDimensions()
                                print "Data space dimensions" 
                                for j in range(0, outputVector.size()):
                                        print "[" + str(j) + "] =" + str(outputVector[j])
                                print "Controller Dimensions"
                                outputVector = testArray.getHeavyDataController(0).getDimensions()
                                for j in range(0, outputVector.size()):
                                        print "[" + str(j) + "] =" + str(outputVector[j])
                                print "Controller size"  + str(testArray.getHeavyDataController(0).getSize())
                                print "Controller starts"
                                outputVector = testArray.getHeavyDataController(0).getStart()
                                for j in range(0, outputVector.size()):
                                        print "[" + str(j) + "] =" + str(outputVector[j])
                                print "Controller strides"
                                outputVector = testArray.getHeavyDataController(0).getStride()
                                for j in range(0, outputVector.size()):
                                        print "[" + str(j) + "] =" + str(outputVector[j])
                                for j in range(0, testArray.getSize()):
                                        print "core #" + str(id) + " testArray[" + str(j) + "] = " + str(testArray.getValueAsInt32(j))
                testArray.accept(exampleWriter)

                readStartVector = UInt32Vector()
                readStartVector.push_back(4*(size - id - 1 - numServersCores))
                readStrideVector = UInt32Vector()
                readStrideVector.push_back(1)
                readCountVector = UInt32Vector()
                readCountVector.push_back(4)
                readDataSizeVector = UInt32Vector()
                readDataSizeVector.push_back(4*(size-numServersCores))

                readArray = XdmfArray.New()

                readArray.initializeAsInt32(0)
                readArray.reserve(testArray.getSize())

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

                readArray.insert(readController)

                if (id == 0):
                        print "\n\n\n"

                print "testing read"
                readArray.read()


                for i in range (0, size):
                        workerComm.Barrier()
                        if (i == id):
                                print "Core # " + str(id)
                                print "Controller stats"
                                print "datasetpath = " + readArray.getHeavyDataController(0).getDataSetPath()
                                print "filepath = " + readArray.getHeavyDataController(0).getFilePath()
                                outputVector = readArray.getHeavyDataController(0).getDataspaceDimensions()
                                print "Data space dimensions"
                                for j in range(0, outputVector.size()):
                                        print "[" + str(j) + "] =" + str(outputVector[j])
                                print "Controller Dimensions"
                                outputVector = readArray.getHeavyDataController(0).getDimensions()
                                for j in range(0, outputVector.size()):
                                        print "[" + str(j) + "] =" + str(outputVector[j])
                                print "Controller size" + str(readArray.getHeavyDataController(0).getSize())
                                print "Controller starts"
                                outputVector = readArray.getHeavyDataController(0).getStart()
                                for j in range(0, outputVector.size()):
                                        print "[" + str(j) + "] =" + str(outputVector[j])
                                print "Controller strides"
                                outputVector = readArray.getHeavyDataController(0).getStride()
                                for j in range(0, outputVector.size()):
                                        print "[" + str(j) + "] =" + str(outputVector[j])
                                for j in range (0, readArray.getSize()):
                                        print "core #" + str(id) + " readArray[" + str(j) + "] = " + str(readArray.getValueAsInt32(j))

                workerComm.Barrier()

                # End of Work Section

        #//stopDSMwriter begin

        if (id == 0):
                exampleWriter.stopDSM()

        #//stopDSMwriter end

        '''
        #//stopDSMcontroller begin


        if (id == 0):
                exampleController.stopDSM()

        #//stopDSMcontroller end

        #//sendDone begin

        if (id == 0):
                closeBuffer = exampleWriter.getServerBuffer()
                closeBuffer.SendDone()

        #//sendDone end

        '''
        #//GetInterComm begin

        exampleDSMComm = exampleWriter.getServerBuffer().GetComm()

        exampleInterComm = exampleDSMComm.GetInterComm()

        #//GetInterComm end

        #//DupInterComm begin

        exampleDSMComm.DupInterComm(exampleInterComm.Dup())

        #//DupInterComm end

        #//SendRecvInfo begin

        if (id >= size - numServersCores):
                exampleWriter.getServerBuffer().SendInfo()
        else:
                exampleWriter.getServerBuffer().ReceiveInfo()

        #//SendRecvInfo end

        '''
        #//restartDSMwriter begin

        exampleWriter.restartDSM()

        #//restartDSMwriter end

        #//restartDSMcontroller begin

        exampleController.restartDSM()

        #//restartDSMcontroller end
        '''

        #//finalizeMPI

        exampleWriter.deleteManager()

        #//finalizeMPI

        '''
        exampleController.deleteManager()
        '''