13
13
14
14
15
15
def init_process (rank , world_size , fn , backend = backend ):
16
- try :
17
- # Initialize the process group
18
- dist .init_process_group (backend , rank = rank , world_size = world_size )
19
- # Call the function
20
- fn (rank , world_size )
21
- except Exception as e :
22
- print (f"Error in process { rank } : { e } " )
23
- traceback .print_exc ()
24
- # Make sure to clean up
25
- if dist .is_initialized ():
26
- dist .destroy_process_group ()
27
- # Return non-zero to indicate error
28
- raise e
16
+ # try:
17
+ # Initialize the process group
18
+ dist .init_process_group (backend , rank = rank , world_size = world_size )
19
+ # Call the function
20
+ fn (rank , world_size )
21
+ # except Exception as e:
22
+ # print(f"Error in process {rank}: {e}")
23
+ # traceback.print_exc()
24
+ # # Make sure to clean up
25
+ # if dist.is_initialized():
26
+ # dist.destroy_process_group()
27
+ # # Return non-zero to indicate error
28
+ # raise e
29
29
30
30
31
31
def run_mcmc (rank , world_size ):
@@ -70,10 +70,10 @@ def two_integrands(x, f):
70
70
if rank == 0 :
71
71
print ("MarkovChainMonteCarlo Result:" , mcmc_result )
72
72
73
- except Exception as e :
74
- print (f"Error in run_mcmc for rank { rank } : { e } " )
75
- traceback .print_exc ()
76
- raise e
73
+ # except Exception as e:
74
+ # print(f"Error in run_mcmc for rank {rank}: {e}")
75
+ # traceback.print_exc()
76
+ # raise e
77
77
finally :
78
78
# Clean up
79
79
if dist .is_initialized ():
@@ -86,21 +86,16 @@ def test_mcmc(world_size=2):
86
86
print (f"Starting with { world_size } processes" )
87
87
88
88
# Start processes with proper error handling
89
- try :
90
- mp .spawn (
91
- init_process ,
92
- args = (world_size , run_mcmc ),
93
- nprocs = world_size ,
94
- join = True ,
95
- daemon = False ,
96
- )
97
- except Exception as e :
98
- print (f"Error in test_mcmc: { e } " )
99
- # Make sure all processes are terminated
100
- # This is handled automatically by spawn when join=True
89
+ mp .spawn (
90
+ init_process ,
91
+ args = (world_size , run_mcmc ),
92
+ nprocs = world_size ,
93
+ join = True ,
94
+ daemon = False ,
95
+ )
101
96
102
97
103
98
# if __name__ == "__main__":
104
- # Prevent issues with multiprocessing on some platforms
105
- # mp.set_start_method("spawn", force=True)
106
- # test_mcmc(2)
99
+ # # Prevent issues with multiprocessing on some platforms
100
+ # mp.set_start_method("spawn", force=True)
101
+ # test_mcmc(2)
0 commit comments