1313
1414
1515def 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
2929
3030
3131def run_mcmc (rank , world_size ):
@@ -70,10 +70,10 @@ def two_integrands(x, f):
7070 if rank == 0 :
7171 print ("MarkovChainMonteCarlo Result:" , mcmc_result )
7272
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
7777 finally :
7878 # Clean up
7979 if dist .is_initialized ():
@@ -86,21 +86,16 @@ def test_mcmc(world_size=2):
8686 print (f"Starting with { world_size } processes" )
8787
8888 # 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+ )
10196
10297
10398# 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