YAC 3.12.0
Yet Another Coupler
Loading...
Searching...
No Matches
test_read_exodus_parallel.c
Go to the documentation of this file.
1// Copyright (c) 2024 The YAC Authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#include <stdlib.h>
6#include <stdio.h>
7#include <string.h>
8#include <math.h>
9#include <unistd.h>
10
11#include "tests.h"
12#include "test_common.h"
13#include "read_icon_grid.h"
14#include "geometry.h"
15#include "grid2vtk.h"
16#include "io_utils.h"
17#include "read_exodus_grid.h"
18#include "grid_file_common.h"
19
20#include <netcdf.h>
21
22#include <mpi.h>
23
29int main(void) {
30
31 MPI_Init(NULL, NULL);
32 xt_initialize(MPI_COMM_WORLD);
33
34 int comm_size, comm_rank;
35
36 MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
37 MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
38
39 if ((comm_size != 4) && (comm_rank == 0)) {
40 fputs("wrong number of processes (has to be four)\n", stderr);
41 exit(EXIT_FAILURE);
42 }
43
44 {
45 char const filename[] = "test_read_exodus_parallel_grid.nc";
46 size_t num_lon = 271, num_lat = 181;
47 double lon_range[] = {-135.0, 135.0}, lat_range[] = {-90.0, 90.0};
48 if (comm_rank == 0)
49 write_dummy_exodus_grid_file(filename, num_lon, num_lat, lon_range, lat_range);
50
51 // ensure that the grid file exists
52 MPI_Barrier(MPI_COMM_WORLD);
53
54 {
55 int use_ll_edges = 0;
56 struct yac_basic_grid * exodus_grid =
58 filename, "exodus", use_ll_edges, MPI_COMM_WORLD);
59
60 size_t local_size =
62
63 if (local_size != ((num_lon - 1) * (num_lat - 1)) / 4)
64 PUT_ERR("ERROR in yac_read_exodus_basic_grid_parallel");
65
66 yac_basic_grid_delete(exodus_grid);
67 }
68
69 // ensure that all tests are completed
70 MPI_Barrier(MPI_COMM_WORLD);
71
72 if (comm_rank == 0) unlink(filename);
73 }
74
75 {
76 char const filename[] = "test_read_exodus_parallel_grid.nc";
77 size_t num_lon = 271, num_lat = 181;
78 double lon_range[] = {0.0, 10.0}, lat_range[] = {80.0, 90.0};
79 if (comm_rank == 0)
80 write_dummy_exodus_grid_file(filename, num_lon, num_lat, lon_range, lat_range);
81
82 // ensure that the grid file exists
83 MPI_Barrier(MPI_COMM_WORLD);
84
85 {
86 int use_ll_edges = 1;
87 struct yac_basic_grid * exodus_grid =
89 filename, "exodus", use_ll_edges, MPI_COMM_WORLD);
90
91 size_t local_size =
93
94 if (local_size != ((num_lon - 1) * (num_lat - 1)) / 4)
95 PUT_ERR("ERROR in yac_read_exodus_basic_grid_parallel");
96
97 yac_basic_grid_delete(exodus_grid);
98 }
99
100 // ensure that all tests are completed
101 MPI_Barrier(MPI_COMM_WORLD);
102
103 if (comm_rank == 0) unlink(filename);
104 }
105
106 xt_finalize();
107 MPI_Finalize();
108
109 return TEST_EXIT_CODE;
110}
size_t yac_basic_grid_get_data_size(struct yac_basic_grid *grid, enum yac_location location)
Definition basic_grid.c:147
void yac_basic_grid_delete(struct yac_basic_grid *grid)
Definition basic_grid.c:70
void write_dummy_exodus_grid_file(char const *grid_filename, size_t num_lon, size_t num_lat, double lon_range[2], double lat_range[2])
@ YAC_LOC_CELL
Definition location.h:14
struct yac_basic_grid * yac_read_exodus_basic_grid_parallel(char const *filename, char const *gridname, int use_ll_edges, MPI_Comm comm)
#define TEST_EXIT_CODE
Definition tests.h:14
#define PUT_ERR(string)
Definition tests.h:10