@@ -517,3 +517,67 @@ def printStats(t, useCom='match', mode='nodes'):
517
517
print ("Info: external com ratio=%f%%" % (volRatio * 100 ))
518
518
if empty == 1 : print ("Warning: at least one processor is empty!" )
519
519
return (varMin , varMax , varRMS , volRatio , empty )
520
+
521
+
522
+ #==================================================================================
523
+ # Efficient distribute
524
+ #==================================================================================
525
+ def _checkNcellsNptsPerProc (ts , NP , isAtCenter = False ):
526
+ ## Calculate and prints the number of cells & points for each proc. Provides a human-readable summary of the MPI distribution.
527
+ import Converter .Mpi as Cmpi
528
+ NPTS = numpy .zeros (NP , dtype = Internal .E_NpyInt )
529
+ NCELLS = numpy .zeros (NP , dtype = Internal .E_NpyInt )
530
+ ##Done by zone for flexibility
531
+ for z in Internal .getZones (ts ):
532
+ proc_num = Cmpi .getProc (z )
533
+ NPTS [proc_num ] += C .getNPts (z )
534
+ if not isAtCenter : NCELLS [proc_num ] += C .getNCells (z )
535
+ else : NCELLS [proc_num ] = NPTS [proc_num ]
536
+
537
+ NPTS = Cmpi .allreduce (NPTS ,op = Cmpi .SUM )
538
+ NCELLS = Cmpi .allreduce (NCELLS ,op = Cmpi .SUM )
539
+ NptsTot = numpy .sum (NPTS )
540
+ NcellsTot = numpy .sum (NCELLS )
541
+ ncells_percent = []
542
+ if Cmpi .rank == 0 :
543
+ for i in range (NP ):
544
+ ncells_percent .append (NCELLS [i ]/ NcellsTot * 100. )
545
+ if isAtCenter : print ('Rank {} has {} cells & {} % of cells' .format (i ,int (NCELLS [i ]),round (ncells_percent [i ],2 )))
546
+ else : print ('Rank {} has {} points & {} cells & {} % of cells' .format (i ,int (NPTS [i ]),int (NCELLS [i ]),round (ncells_percent [i ],2 )))
547
+
548
+ if isAtCenter : print ('All points: {} million cells' .format (NcellsTot / 1.e6 ))
549
+ else : print ('All points: {} million points & {} million cells' .format (NptsTot / 1.e6 ,NcellsTot / 1.e6 ))
550
+ print ('Range of % of cells: {} - {}' .format (round (min (ncells_percent ),2 ),round (max (ncells_percent ),2 )))
551
+
552
+ return None
553
+
554
+
555
+ def _write2pathLocal__ (tsLocal , tLocal ):
556
+ ##Modifies the .Solver#Param/proc only in the files
557
+ import Converter .Mpi as Cmpi
558
+ import Converter .Filter as Filter
559
+ paths = []; ns = []
560
+ bases = Internal .getBases (tsLocal )
561
+ for b in bases :
562
+ zones = Internal .getZones (b )
563
+ for z in zones :
564
+ nodes = Internal .getNodesFromName2 (z , 'proc' )
565
+ for n in nodes :
566
+ p = 'CGNSTree/%s/%s/.Solver#Param/proc' % (b [0 ],z [0 ])
567
+ paths .append (p ); ns .append (n )
568
+ Filter .writeNodesFromPaths (tLocal , paths , ns , maxDepth = 0 , mode = 1 )
569
+
570
+
571
+ def _distributeSkeletonTree (tIn , NP , algorithm = 'graph' , useCom = 'ID' ):
572
+ """Distribute PyTrees over NP processors. t is a list with the file names.
573
+ Usage: _distributeSkeletonTree(t=[], NP, algorithm='graph', useCom='all')"""
574
+ import Converter .Mpi as Cmpi
575
+ fileNameLength = len (tIn )
576
+ for fileName in tIn :
577
+ ts = Cmpi .convertFile2SkeletonTree (fileName , maxDepth = 3 )
578
+ stats = _distribute (ts , NP , algorithm = algorithm , useCom = useCom )
579
+ _write2pathLocal__ (ts , fileName )
580
+ if fileName == tIn [0 ]: tcs = Internal .copyTree (ts )
581
+ if fileNameLength > 1 and fileName != tIn [0 ]: _copyDistribution (ts , tcs )
582
+ _checkNcellsNptsPerProc (tcs ,NP )
583
+ return None
0 commit comments