This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfompi_win_free.c
150 lines (116 loc) · 4.94 KB
/
fompi_win_free.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Copyright (c) 2012 The Trustees of University of Illinois. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdlib.h>
#include "fompi.h"
int foMPI_Win_free(foMPI_Win *win) {
dmapp_pe_t pe = (*win)->commrank;
int i;
foMPI_Win_dynamic_element_t* current;
foMPI_Win_dynamic_element_t* previous;
/* TODO: Could this be removed? */
MPI_Barrier((*win)->comm);
if ( (*win)->create_flavor == foMPI_WIN_FLAVOR_DYNAMIC ) {
for( i = 0 ; i<(*win)->commsize ; i++ ) {
if( i == pe ) {
while( (*win)->win_dynamic_mem_regions != NULL ) {
_foMPI_mem_unregister(&((*win)->win_dynamic_mem_regions->seg),*win);
_foMPI_mem_unregister(&((*win)->win_dynamic_mem_regions_seg), *win);
previous = (*win)->win_dynamic_mem_regions;
(*win)->win_dynamic_mem_regions_seg = (*win)->win_dynamic_mem_regions->next_seg; /* TODO: just use pointer? */
(*win)->win_dynamic_mem_regions = (*win)->win_dynamic_mem_regions->next;
_foMPI_FREE( previous );
}
} else {
if ( (*win)->dynamic_list[i].remote_mem_regions != NULL ) {
current = (*win)->dynamic_list[i].remote_mem_regions;
while( current->next != NULL ) {
previous = current;
current = current->next;
_foMPI_FREE( previous );
}
_foMPI_FREE( current );
}
}
}
_foMPI_mem_unregister(&((*win)->dynamic_list[pe].win_ptr_seg), *win);
_foMPI_mem_unregister(&((*win)->dynamic_list[pe].pscw_matching_exposure_seg), *win);
_foMPI_FREE((*win)->dynamic_list[pe].pscw_matching_exposure);
_foMPI_FREE((*win)->dynamic_list);
} else {
#ifdef XPMEM
/* unmap the remote memory */
for( i=0 ; i<(*win)->onnode_size ; i++ ) {
if ((*win)->xpmem_array[i].base_apid != -1) {
//printf("%i: unmap base\n", debug_pe);
foMPI_unmap_memory_xpmem( &((*win)->xpmem_array[i].base_apid), (*win)->xpmem_array[i].base, (*win)->xpmem_array[i].base_offset );
}
foMPI_unmap_memory_xpmem( &((*win)->xpmem_array[i].win_ptr_apid), (*win)->xpmem_array[i].win_ptr, (*win)->xpmem_array[i].win_ptr_offset );
foMPI_unmap_memory_xpmem( &((*win)->xpmem_array[i].pscw_matching_exposure_apid), (*win)->xpmem_array[i].pscw_matching_exposure, (*win)->xpmem_array[i].pscw_matching_exposure_offset );
foMPI_unmap_memory_xpmem( &((*win)->xpmem_array[i].notif_queue_apid), (*win)->xpmem_array[i].notif_queue, (*win)->xpmem_array[i].notif_queue_offset );
foMPI_unmap_memory_xpmem( &((*win)->xpmem_array[i].notif_queue_state_apid), (*win)->xpmem_array[i].notif_queue_state, (*win)->xpmem_array[i].notif_queue_state_offset );
}
_foMPI_FREE( (*win)->xpmem_array );
#endif
if ( (*win)->win_array[pe].base != NULL ) {
_foMPI_mem_unregister(&((*win)->win_array[pe].seg),*win);
#ifdef XPMEM
if ((*win)->xpmem_segdesc.base.seg != -1 ) {
//printf("%i: unexport base\n", debug_pe);
foMPI_unexport_memory_xpmem( (*win)->xpmem_segdesc.base );
}
#endif
}
if ( (*win)->create_flavor == foMPI_WIN_FLAVOR_ALLOCATE ) {
_foMPI_FREE( (*win)->win_array[pe].base );
}
_foMPI_mem_unregister(&((*win)->win_array[pe].win_ptr_seg),*win);
#ifdef XPMEM
foMPI_unexport_memory_xpmem( (*win)->xpmem_segdesc.win_ptr );
#endif
_foMPI_mem_unregister(&((*win)->win_array[pe].pscw_matching_exposure_seg), *win);
#ifdef XPMEM
foMPI_unexport_memory_xpmem( (*win)->xpmem_segdesc.pscw_matching_exposure );
foMPI_unexport_memory_xpmem( (*win)->xpmem_segdesc.notif_queue );
foMPI_unexport_memory_xpmem( (*win)->xpmem_segdesc.notif_queue_state );
#endif
xpmem_notif_free_queue(*win);
_foMPI_FREE((*win)->win_array[pe].pscw_matching_exposure);
_foMPI_FREE((*win)->win_array);
#ifdef XPMEM
if ( (*win)->onnode_lower_bound == -1 ) {
_foMPI_FREE( (*win)->onnode_ranks );
}
MPI_Group_free( &((*win)->win_onnode_group) );
MPI_Comm_free( &((*win)->win_onnode_comm) );
#endif
}
_foMPI_FREE((*win)->pscw_matching_access);
#ifdef UGNI
_fompi_notif_uq_finalize(&((*win)->destination_cq_discarded));
_foMPI_TRACE_LOG(3, "fompi_oset Finalize \n");
#endif
/* free remainder of exclusive locks list
* at this point, if the programm is MPI consistent, there shouldn't be a element in the list */
if( (*win)->excl_locks != NULL ) {
foMPI_Win_excl_lock_elem_t* previous;
foMPI_Win_excl_lock_elem_t* current;
previous = (*win)->excl_locks;
current = (*win)->excl_locks->next;
while( current != NULL ) {
_foMPI_FREE( previous );
previous = current;
current = current->next;
}
_foMPI_FREE( previous ); /* free last element */
(*win)->excl_locks = NULL;
}
_foMPI_FREE((*win)->group_ranks);
if ( (*win)->name != NULL ) {
_foMPI_FREE( (*win)->name );
}
MPI_Barrier( (*win)->comm );
_foMPI_FREE(*win);
*win = foMPI_WIN_NULL;
return MPI_SUCCESS;
}