@@ -6,97 +6,121 @@ Parition mesh using Nek5000's vertex connectivity (con) file.
6
6
#include <stdlib.h>
7
7
#include <mpi.h>
8
8
9
- #include "conReader.h"
9
+ #include <gencon.h>
10
+ #include <genmap.h>
11
+ #include <parRSB.h>
10
12
11
- #include "gslib.h"
12
- #include "parRSB.h"
13
13
#include "quality.h"
14
14
15
15
#define MAXNV 8 /* maximum number of vertices per element */
16
16
typedef struct {
17
17
int proc ;
18
- long long id ;
19
18
long long vtx [MAXNV ];
20
19
} elm_data ;
21
20
21
+ #define EXIT_ERROR () do{\
22
+ MPI_Finalize();\
23
+ return EXIT_FAILURE;\
24
+ } while(0)
25
+
22
26
int 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
+ }
27
37
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 ];
31
40
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 );
34
48
35
49
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 );
36
53
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 ;
41
57
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 );
44
61
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 );
48
67
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 );
53
70
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 ;
58
77
78
+ /* Partition the mesh */
79
+ int options [3 ];
59
80
options [0 ] = 1 ; /* use custom options */
60
- options [1 ] = 3 ; /* debug level */
81
+ options [1 ] = 2 ; /* debug level */
61
82
options [2 ] = 0 ; /* not used */
62
83
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
+ }
65
92
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 ];
73
102
}
74
103
}
75
- free (part );
76
- conFree (& con );
104
+ elements .n = nelt ;
77
105
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 );
80
109
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 ];
89
117
}
90
118
}
119
+ array_free (& elements );
91
120
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 );
98
122
99
- quit :
100
- MPI_Finalize ( );
101
- return ierr ;
123
+ if ( part ) free ( part );
124
+ if ( vl ) free ( vl );
125
+ if ( coord ) free ( coord ) ;
102
126
}
0 commit comments