8
8
import atexit
9
9
import signal
10
10
import asyncio
11
+ import queue
12
+ import threading
13
+ import time
11
14
from collections import defaultdict
12
- from datetime import datetime
15
+
13
16
try :
14
17
import mpi4py
15
18
from mpi4py import futures
51
54
# The global variable is responsible for if MPI backend has already been initialized
52
55
is_mpi_initialized = False
53
56
54
- import queue
55
- import threading
56
- import time
57
57
58
58
exitFlag = 0
59
59
60
- class myThread (threading .Thread ):
61
- def __init__ (self , threadID , name , q ):
62
- threading .Thread .__init__ (self )
63
- self .threadID = threadID
64
- self .name = name
65
- self .q = q
66
- def run (self ):
67
- print ("Starting " + self .name )
68
- process_data (self .name , self .q )
69
- print ("Exiting " + self .name )
70
60
61
+ class myThread (threading .Thread ):
62
+ def __init__ (self , threadID , name , q ):
63
+ threading .Thread .__init__ (self )
64
+ self .threadID = threadID
65
+ self .name = name
66
+ self .q = q
71
67
68
+ def run (self ):
69
+ print ("Starting " + self .name )
70
+ process_data (self .name , self .q )
71
+ print ("Exiting " + self .name )
72
72
73
73
74
74
def process_data (threadName , q ):
75
75
global getRequests
76
76
while not exitFlag :
77
77
queueLock .acquire ()
78
- #print("queue size is {} , time ={}".format(workQueue.qsize(),datetime.fromtimestamp(time.time())))
78
+ # print("queue size is {} , time ={}".format(workQueue.qsize(),datetime.fromtimestamp(time.time())))
79
79
if not workQueue .empty ():
80
- future , data = q .get ()
80
+ future , data = q .get ()
81
81
queueLock .release ()
82
- function , args = data
82
+ function , args = data
83
83
result = function (* args )
84
84
if future :
85
85
future .set_result (result )
86
86
else :
87
87
queueLock .release ()
88
- #time.sleep(.1)
88
+ # time.sleep(.1)
89
89
print ("exited" )
90
90
91
+
91
92
threadList = ["Thread-1" ]
92
93
queueLock = threading .Lock ()
93
94
workQueue = queue .Queue (0 )
94
- getQueue = queue .Queue (0 )
95
95
threads = []
96
96
97
97
@@ -122,12 +122,12 @@ def init():
122
122
comm = MPI .COMM_WORLD
123
123
rank = comm .Get_rank ()
124
124
parent_comm = MPI .Comm .Get_parent ()
125
- if not threads and rank == 0 and parent_comm == MPI .COMM_NULL :
125
+ if not threads and rank == 0 and parent_comm == MPI .COMM_NULL :
126
126
for tName in threadList :
127
127
thread = myThread (1 , tName , workQueue )
128
128
thread .start ()
129
129
threads .append (thread )
130
-
130
+
131
131
# path to dynamically spawn MPI processes
132
132
if rank == 0 and parent_comm == MPI .COMM_NULL :
133
133
# Create new threads
@@ -231,7 +231,6 @@ def shutdown():
231
231
"""
232
232
global exitFlag
233
233
exitFlag = 1
234
- print ("here" )
235
234
for t in threads :
236
235
t .join ()
237
236
mpi_state = communication .MPIState .get_instance ()
@@ -245,7 +244,6 @@ def shutdown():
245
244
async_operations .finish ()
246
245
if not MPI .Is_finalized ():
247
246
MPI .Finalize ()
248
-
249
247
250
248
251
249
def cluster_resources ():
@@ -283,12 +281,11 @@ def put(data):
283
281
unidist.core.backends.mpi.core.common.MasterDataID
284
282
An ID of an object in object storage.
285
283
"""
286
- #data_id = object_store.generate_data_id(garbage_collector)
287
- data_id = futures .Future ()
288
- workQueue .put ([data_id , [ object_store .generate_data_id ,[garbage_collector ]] ])
284
+ # data_id = object_store.generate_data_id(garbage_collector)
285
+ data_id = futures .Future ()
286
+ workQueue .put ([data_id , [object_store .generate_data_id , [garbage_collector ]]])
289
287
data_id = data_id .result ()
290
- workQueue .put ([ None , [object_store .put ,[data_id , data ]] ])
291
- #object_store.put(data_id, data)
288
+ workQueue .put ([None , [object_store .put , [data_id , data ]]])
292
289
293
290
logger .debug ("PUT {} id" .format (data_id ._id ))
294
291
@@ -311,26 +308,16 @@ def get(data_ids):
311
308
"""
312
309
313
310
def get_impl (data_id ):
314
- global getRequests ,workQueue
311
+ global getRequests , workQueue
315
312
if object_store .contains (data_id ):
316
313
value = object_store .get (data_id )
317
314
else :
318
315
queueLock .acquire ()
319
- print ("size {} data_id={}" .format (workQueue .qsize (), data_id ))
320
- future = futures .Future ()
321
- workQueue .put ([future , [ request_worker_data , [data_id ] ] ])
316
+ print ("size {} data_id={}" .format (workQueue .qsize (), data_id ))
317
+ future = futures .Future ()
318
+ workQueue .put ([future , [request_worker_data , [data_id ]] ])
322
319
queueLock .release ()
323
- value = future .result ()
324
-
325
-
326
- print ("got {}" .format ( data_id ))
327
- print ("value {}" .format ( value ))
328
-
329
-
330
-
331
-
332
-
333
-
320
+ value = future .result ()
334
321
335
322
if isinstance (value , Exception ):
336
323
raise value
@@ -449,8 +436,16 @@ def submit(task, *args, num_returns=1, **kwargs):
449
436
# dest_rank, garbage_collector, num_returns
450
437
# )
451
438
global workQueue
452
- output_ids = futures .Future ()
453
- workQueue .put ([output_ids , [ object_store .generate_output_data_id ,[dest_rank , garbage_collector , num_returns ]] ])
439
+ output_ids = futures .Future ()
440
+ workQueue .put (
441
+ [
442
+ output_ids ,
443
+ [
444
+ object_store .generate_output_data_id ,
445
+ [dest_rank , garbage_collector , num_returns ],
446
+ ],
447
+ ]
448
+ )
454
449
output_ids = output_ids .result ()
455
450
logger .debug ("REMOTE OPERATION" )
456
451
logger .debug (
@@ -466,16 +461,13 @@ def submit(task, *args, num_returns=1, **kwargs):
466
461
467
462
unwrapped_args = [common .unwrap_data_ids (arg ) for arg in args ]
468
463
unwrapped_kwargs = {k : common .unwrap_data_ids (v ) for k , v in kwargs .items ()}
469
-
470
-
464
+
471
465
queueLock .acquire ()
472
466
print (workQueue .qsize ())
473
- workQueue .put ([ None , [ push_data , [dest_rank , unwrapped_args ]]])
474
-
475
- print (unwrapped_args , time .time ())
476
- workQueue .put ([ None , [ push_data , [dest_rank , unwrapped_kwargs ]]])
467
+ workQueue .put ([None , [push_data , [dest_rank , unwrapped_args ]]])
477
468
478
-
469
+ print (unwrapped_args , time .time ())
470
+ workQueue .put ([None , [push_data , [dest_rank , unwrapped_kwargs ]]])
479
471
480
472
operation_type = common .Operation .EXECUTE
481
473
operation_data = {
@@ -484,19 +476,22 @@ def submit(task, *args, num_returns=1, **kwargs):
484
476
"kwargs" : unwrapped_kwargs ,
485
477
"output" : common .master_data_ids_to_base (output_ids ),
486
478
}
479
+
487
480
def send_operation_impl (comm , operation_type , operation_data , dest_rank ):
488
481
async_operations = AsyncOperations .get_instance ()
489
482
h_list , _ = communication .isend_complex_operation (
490
- comm ,
491
- operation_type ,
492
- operation_data ,
493
- dest_rank ,
483
+ comm ,
484
+ operation_type ,
485
+ operation_data ,
486
+ dest_rank ,
494
487
)
495
488
async_operations .extend (h_list )
489
+
496
490
comm = communication .MPIState .get_instance ().comm
497
- workQueue .put ([ None , [ send_operation_impl , [comm , operation_type , operation_data , dest_rank ]]])
498
-
499
-
491
+ workQueue .put (
492
+ [None , [send_operation_impl , [comm , operation_type , operation_data , dest_rank ]]]
493
+ )
494
+
500
495
queueLock .release ()
501
496
# Track the task execution
502
497
garbage_collector .increment_task_counter ()
@@ -507,8 +502,6 @@ def send_operation_impl(comm, operation_type, operation_data, dest_rank):
507
502
# ---------------------------- #
508
503
# unidist termination handling #
509
504
# ---------------------------- #
510
- #!/usr/bin/python
511
-
512
505
513
506
514
507
def _termination_handler ():
0 commit comments