OpenMPI 0.1.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

allocator_basic.h
Go to the documentation of this file.
1 /**
2 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3 * University Research and Technology
4 * Corporation. All rights reserved.
5 * Copyright (c) 2004-2005 The University of Tennessee and The University
6 * of Tennessee Research Foundation. All rights
7 * reserved.
8 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9 * University of Stuttgart. All rights reserved.
10 * Copyright (c) 2004-2005 The Regents of the University of California.
11 * All rights reserved.
12 * $COPYRIGHT$
13 *
14 * Additional copyrights may follow
15 *
16 * $HEADER$
17 */
18
19 /** @file
20 * A generic memory basic allocator.
21 **/
22
23 #ifndef ALLOCATOR_BASIC_H
24 #define ALLOCATOR_BASIC_H
25
26 #include "ompi_config.h"
27 #include <stdlib.h>
28 #include <string.h>
29 #include "opal/threads/mutex.h"
30 #include "ompi/class/ompi_free_list.h"
31 #include "ompi/mca/allocator/allocator.h"
32
33
34 /*
35 * Free list of allocated segments
36 */
37
38 struct mca_allocator_basic_segment_t {
39 ompi_free_list_item_t seg_item;
40 unsigned char* seg_addr;
41 size_t seg_size;
42 };
43 typedef struct mca_allocator_basic_segment_t mca_allocator_basic_segment_t;
44
45
46 /*
47 * Basic allocator module
48 */
49
50 struct mca_allocator_basic_module_t {
51 mca_allocator_base_module_t super;
52 mca_allocator_base_component_segment_alloc_fn_t seg_alloc;
53 mca_allocator_base_component_segment_free_fn_t seg_free;
54 opal_list_t seg_list;
55 opal_mutex_t seg_lock;
56 ompi_free_list_t seg_descriptors;
57 };
58 typedef struct mca_allocator_basic_module_t mca_allocator_basic_module_t;
59
60
61 BEGIN_C_DECLS
62
63 /*
64 * Component open/cleanup.
65 */
66
67 int mca_allocator_basic_component_open(void);
68 int mca_allocator_basic_component_close(void);
69
70 /**
71 * The function used to initialize the component.
72 */
73 mca_allocator_base_module_t* mca_allocator_basic_component_init(
74 bool enable_mpi_threads,
75 mca_allocator_base_component_segment_alloc_fn_t segment_alloc,
76 mca_allocator_base_component_segment_free_fn_t segment_free,
77 struct mca_mpool_base_module_t* module
78 );
79
80 /**
81 * Accepts a request for memory in a specific region defined by the
82 * mca_allocator_basic_options_t struct and returns a pointer to memory in that
83 * region or NULL if there was an error
84 *
85 * @param mem A pointer to the appropriate struct for the area of memory.
86 * @param size The size of the requested area of memory
87 *
88 * @retval Pointer to the area of memory if the allocation was successful
89 * @retval NULL if the allocation was unsuccessful
90 */
91 void * mca_allocator_basic_alloc(
92 mca_allocator_base_module_t * mem,
93 size_t size,
94 size_t align,
95 mca_mpool_base_registration_t** registration);
96
97 /**
98 * Attempts to resize the passed region of memory into a larger or a smaller
99 * region. If it is unsuccessful, it will return NULL and the passed area of
100 * memory will be untouched.
101 *
102 * @param mem A pointer to the appropriate struct for the area of
103 * memory.
104 * @param size The size of the requested area of memory
105 * @param ptr A pointer to the region of memory to be resized
106 *
107 * @retval Pointer to the area of memory if the reallocation was successful
108 * @retval NULL if the allocation was unsuccessful
109 *
110 */
111 void * mca_allocator_basic_realloc(
112 mca_allocator_base_module_t * mem,
113 void * ptr,
114 size_t size,
115 mca_mpool_base_registration_t** registration);
116
117 /**
118 * Frees the passed region of memory
119 *
120 * @param mem A pointer to the appropriate struct for the area of
121 * memory.
122 * @param ptr A pointer to the region of memory to be freed
123 *
124 * @retval None
125 *
126 */
127 void mca_allocator_basic_free(
128 mca_allocator_base_module_t * mem,
129 void * ptr);
130
131 /**
132 * Frees all the memory from all the basics back to the system. Note that
133 * this function only frees memory that was previously freed with
134 * mca_allocator_basic_free().
135 *
136 * @param mem A pointer to the appropriate struct for the area of
137 * memory.
138 *
139 * @retval None
140 *
141 */
142 int mca_allocator_basic_compact(
143 mca_allocator_base_module_t * mem);
144
145 /**
146 * Cleanup all resources held by this allocator.
147 *
148 * @param mem A pointer to the appropriate struct for the area of
149 * memory.
150 *
151 * @retval None
152 *
153 */
154 int mca_allocator_basic_finalize(
155 mca_allocator_base_module_t * mem);
156
157 OMPI_DECLSPEC extern mca_allocator_base_component_t mca_allocator_basic_component;
158
159 END_C_DECLS
160
161 #endif /* ALLOCATOR_BUCKET_ALLOC_H */
162
163
164
165
166
167
168
mca_allocator_basic_alloc
void * mca_allocator_basic_alloc(mca_allocator_base_module_t *mem, size_t size, size_t align, mca_mpool_base_registration_t **registration)
Accepts a request for memory in a specific region defined by the mca_allocator_basic_options_t struct...
Definition: allocator_basic.c:160
mca_allocator_basic_module_t
Definition: allocator_basic.h:50
mca_allocator_basic_realloc
void * mca_allocator_basic_realloc(mca_allocator_base_module_t *mem, void *ptr, size_t size, mca_mpool_base_registration_t **registration)
Attempts to resize the passed region of memory into a larger or a smaller region. ...
Definition: allocator_basic.c:243
opal_mutex_t
Definition: mutex_unix.h:53
mca_allocator_basic_component_init
mca_allocator_base_module_t * mca_allocator_basic_component_init(bool enable_mpi_threads, mca_allocator_base_component_segment_alloc_fn_t segment_alloc, mca_allocator_base_component_segment_free_fn_t segment_free, struct mca_mpool_base_module_t *module)
The function used to initialize the component.
Definition: allocator_basic.c:74
mca_mpool_base_registration_t
Definition: mpool.h:44
mca_allocator_basic_compact
int mca_allocator_basic_compact(mca_allocator_base_module_t *mem)
Frees all the memory from all the basics back to the system.
Definition: allocator_basic.c:355
mca_allocator_base_component_segment_free_fn_t
void(* mca_allocator_base_component_segment_free_fn_t)(struct mca_mpool_base_module_t *module, void *segment)
A function to free memory from the control of the allocator framework back to the system...
Definition: allocator.h:113
mca_allocator_base_component_segment_alloc_fn_t
void *(* mca_allocator_base_component_segment_alloc_fn_t)(struct mca_mpool_base_module_t *module, size_t *size, mca_mpool_base_registration_t **registration)
A function to get more memory from the system.
Definition: allocator.h:103
ompi_free_list_t
Definition: ompi_free_list.h:39
mca_allocator_base_component_2_0_0_t
The data structure provided by each component to the framework which describes the component...
Definition: allocator.h:133
ompi_free_list_item_t
Definition: ompi_free_list.h:62
mca_allocator_basic_finalize
int mca_allocator_basic_finalize(mca_allocator_base_module_t *mem)
Cleanup all resources held by this allocator.
Definition: allocator_basic.c:370
mca_allocator_basic_free
void mca_allocator_basic_free(mca_allocator_base_module_t *mem, void *ptr)
Frees the passed region of memory.
Definition: allocator_basic.c:272
opal_list_t
Definition: opal_list.h:147
allocator.h
Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana University Research and Techno...
mutex.h
Mutual exclusion functions.
mca_allocator_base_module_t
The data structure for each component.
Definition: allocator.h:78
mca_mpool_base_module_t
mpool module descriptor.
Definition: mpool.h:174
mca_allocator_basic_segment_t
Definition: allocator_basic.h:38