@@ -6,97 +6,121 @@ Parition mesh using Nek5000's vertex connectivity (con) file.
66#include <stdlib.h>
77#include <mpi.h>
88
9- #include "conReader.h"
9+ #include <gencon.h>
10+ #include <genmap.h>
11+ #include <parRSB.h>
1012
11- #include "gslib.h"
12- #include "parRSB.h"
1313#include "quality.h"
1414
1515#define MAXNV 8 /* maximum number of vertices per element */
1616typedef struct {
1717 int proc ;
18- long long id ;
1918 long long vtx [MAXNV ];
2019} elm_data ;
2120
21+ #define EXIT_ERROR () do{\
22+ MPI_Finalize();\
23+ return EXIT_FAILURE;\
24+ } while(0)
25+
2226int main (int argc , char * argv []) {
23- struct comm comm ;
24- struct crystal cr ;
25- struct array eList ;
26- elm_data * data ;
27+ MPI_Init (& argc , & argv );
28+ int rank ,size ;
29+ MPI_Comm_rank (MPI_COMM_WORLD ,& rank );
30+ MPI_Comm_size (MPI_COMM_WORLD ,& size );
31+
32+ if (argc != 3 ){
33+ if (rank == 0 )
34+ printf ("Usage: %s <#nread> <mesh file>\n" ,argv [0 ]);
35+ EXIT_ERROR ();
36+ }
2737
28- int ierr ;
29- int e , n , nel , nv ;
30- int options [3 ];
38+ int n_read = atoi (argv [1 ]);
39+ char * mesh_name = argv [2 ];
3140
32- MPI_Init (& argc , & argv );
33- comm_init (& comm , MPI_COMM_WORLD );
41+ char geom_name [BUFSIZ ];
42+ strncpy (geom_name ,mesh_name ,BUFSIZ );
43+ strncat (geom_name ,".re2" ,BUFSIZ );
44+
45+ char conn_name [BUFSIZ ];
46+ strncpy (conn_name ,mesh_name ,BUFSIZ );
47+ strncat (conn_name ,".co2" ,BUFSIZ );
3448
3549 int color = MPI_UNDEFINED ;
50+ if (rank < n_read ) color = 1 ;
51+ MPI_Comm comm_read ;
52+ MPI_Comm_split (MPI_COMM_WORLD , color , 0 , & comm_read );
3653
37- if (argc != 3 ) {
38- if (comm .id ) printf ("usage: ./example <#nread> <co2 file>\n" );
39- return EXIT_FAILURE ;
40- }
54+ long long * vl = NULL ;
55+ double * coord = NULL ;
56+ int nelt = 0 ,ndim ,nv ;
4157
42- int nRead = atoi (argv [1 ]);
43- char * conFile = argv [2 ];
58+ /* Read mesh data */
59+ if (color == 1 ){
60+ struct comm comm ; comm_init (& comm , comm_read );
4461
45- if (comm .id < nRead ) color = 1 ;
46- MPI_Comm comm_read ;
47- MPI_Comm_split (comm .c , color , 0 , & comm_read );
62+ Mesh mesh ;
63+ read_geometry (& mesh ,geom_name ,& comm );
64+ read_connectivity (mesh ,conn_name ,& comm );
65+ get_vertex_ids (& vl ,mesh );
66+ get_vertex_coordinates (& coord ,mesh );
4867
49- ierr = 0 ;
50- struct con con = {};
51- if (color != MPI_UNDEFINED ) ierr = conRead (conFile , & con , comm_read );
52- if (ierr ) goto quit ;
68+ ndim = get_mesh_dim (mesh );
69+ nelt = get_mesh_nel (mesh );
5370
54- comm_bcast (& comm , & con .nv , sizeof (int ), 0 );
55- nv = con .nv ;
56- nel = con .nel ;
57- int * part = (int * ) malloc (nel * sizeof (int ));
71+ mesh_free (mesh );
72+ comm_free (& comm );
73+ }
74+
75+ MPI_Bcast (& ndim ,1 ,MPI_INT ,0 ,MPI_COMM_WORLD );
76+ nv = (ndim == 3 )?8 :4 ;
5877
78+ /* Partition the mesh */
79+ int options [3 ];
5980 options [0 ] = 1 ; /* use custom options */
60- options [1 ] = 3 ; /* debug level */
81+ options [1 ] = 2 ; /* debug level */
6182 options [2 ] = 0 ; /* not used */
6283
63- ierr = parRSB_partMesh (part , con .vl , nel , nv , options , comm .c );
64- if (ierr ) goto quit ;
84+ int * part = (int * )calloc (nelt ,sizeof (int ));
85+ int ierr = parRSB_partMesh (part ,vl ,coord ,nelt ,nv ,options ,MPI_COMM_WORLD );
86+ if (ierr ){
87+ if (vl ) free (vl );
88+ if (coord ) free (coord );
89+ if (part ) free (part );
90+ EXIT_ERROR ();
91+ }
6592
66- /* redistribute data */
67- array_init (elm_data , & eList , nel ), eList .n = nel ;
68- for (data = eList .ptr , e = 0 ; e < nel ; ++ e ) {
69- data [e ].proc = part [e ];
70- data [e ].id = con .el [e ];
71- for (n = 0 ; n < nv ; ++ n ) {
72- data [e ].vtx [n ] = con .vl [e * nv + n ];
93+ /* Redistribute data */
94+ struct array elements ;
95+ array_init (elm_data ,& elements ,nelt );
96+ elm_data * data ;
97+ int e ,n ;
98+ for (data = elements .ptr ,e = 0 ; e < nelt ; ++ e ) {
99+ data [e ].proc = part [e ];
100+ for (n = 0 ; n < nv ; ++ n ) {
101+ data [e ].vtx [n ] = vl [e * nv + n ];
73102 }
74103 }
75- free (part );
76- conFree (& con );
104+ elements .n = nelt ;
77105
78- crystal_init (& cr , & comm );
79- sarray_transfer (elm_data , & eList , proc , 0 , & cr );
106+ struct comm comm ; comm_init (& comm ,MPI_COMM_WORLD );
107+ struct crystal cr ; crystal_init (& cr , & comm );
108+ sarray_transfer (elm_data ,& elements ,proc ,0 ,& cr );
80109 crystal_free (& cr );
81- nel = eList .n ;
82-
83- long long * el = (long long * ) malloc (nel * sizeof (long long ));
84- long long * vl = (long long * ) malloc (nv * nel * sizeof (long long ));
85- for (data = eList .ptr , e = 0 ; e < nel ; ++ e ) {
86- el [e ] = data [e ].id ;
87- for (n = 0 ; n < nv ; ++ n ) {
88- vl [e * nv + n ] = data [e ].vtx [n ];
110+ comm_free (& comm );
111+
112+ nelt = elements .n ;
113+ vl = (long long * ) malloc (nv * nelt * sizeof (long long ));
114+ for (data = elements .ptr , e = 0 ; e < nelt ; ++ e ) {
115+ for (n = 0 ; n < nv ; ++ n ){
116+ vl [e * nv + n ]= data [e ].vtx [n ];
89117 }
90118 }
119+ array_free (& elements );
91120
92- printPartStat (vl , nel , nv , comm .c );
93-
94- free (el );
95- free (vl );
96- array_free (& eList );
97- comm_free (& comm );
121+ printPartStat (vl , nelt , nv , MPI_COMM_WORLD );
98122
99- quit :
100- MPI_Finalize ( );
101- return ierr ;
123+ if ( part ) free ( part );
124+ if ( vl ) free ( vl );
125+ if ( coord ) free ( coord ) ;
102126}
0 commit comments