
such, the commit message back to the master SVN repository is fairly long. = ORTE Job-Level Output Messages = Add two new interfaces that should be used for all new code throughout the ORTE and OMPI layers (we already make the search-and-replace on the existing ORTE / OMPI layers): * orte_output(): (and corresponding friends ORTE_OUTPUT, orte_output_verbose, etc.) This function sends the output directly to the HNP for processing as part of a job-specific output channel. It supports all the same outputs as opal_output() (syslog, file, stdout, stderr), but for stdout/stderr, the output is sent to the HNP for processing and output. More on this below. * orte_show_help(): This function is a drop-in-replacement for opal_show_help(), with two differences in functionality: 1. the rendered text help message output is sent to the HNP for display (rather than outputting directly into the process' stderr stream) 1. the HNP detects duplicate help messages and does not display them (so that you don't see the same error message N times, once from each of your N MPI processes); instead, it counts "new" instances of the help message and displays a message every ~5 seconds when there are new ones ("I got X new copies of the help message...") opal_show_help and opal_output still exist, but they only output in the current process. The intent for the new orte_* functions is that they can apply job-level intelligence to the output. As such, we recommend that all new ORTE and OMPI code use the new orte_* functions, not thei opal_* functions. === New code === For ORTE and OMPI programmers, here's what you need to do differently in new code: * Do not include opal/util/show_help.h or opal/util/output.h. Instead, include orte/util/output.h (this one header file has declarations for both the orte_output() series of functions and orte_show_help()). * Effectively s/opal_output/orte_output/gi throughout your code. Note that orte_output_open() takes a slightly different argument list (as a way to pass data to the filtering stream -- see below), so you if explicitly call opal_output_open(), you'll need to slightly adapt to the new signature of orte_output_open(). * Literally s/opal_show_help/orte_show_help/. The function signature is identical. === Notes === * orte_output'ing to stream 0 will do similar to what opal_output'ing did, so leaving a hard-coded "0" as the first argument is safe. * For systems that do not use ORTE's RML or the HNP, the effect of orte_output_* and orte_show_help will be identical to their opal counterparts (the additional information passed to orte_output_open() will be lost!). Indeed, the orte_* functions simply become trivial wrappers to their opal_* counterparts. Note that we have not tested this; the code is simple but it is quite possible that we mucked something up. = Filter Framework = Messages sent view the new orte_* functions described above and messages output via the IOF on the HNP will now optionally be passed through a new "filter" framework before being output to stdout/stderr. The "filter" OPAL MCA framework is intended to allow preprocessing to messages before they are sent to their final destinations. The first component that was written in the filter framework was to create an XML stream, segregating all the messages into different XML tags, etc. This will allow 3rd party tools to read the stdout/stderr from the HNP and be able to know exactly what each text message is (e.g., a help message, another OMPI infrastructure message, stdout from the user process, stderr from the user process, etc.). Filtering is not active by default. Filter components must be specifically requested, such as: {{{ $ mpirun --mca filter xml ... }}} There can only be one filter component active. = New MCA Parameters = The new functionality described above introduces two new MCA parameters: * '''orte_base_help_aggregate''': Defaults to 1 (true), meaning that help messages will be aggregated, as described above. If set to 0, all help messages will be displayed, even if they are duplicates (i.e., the original behavior). * '''orte_base_show_output_recursions''': An MCA parameter to help debug one of the known issues, described below. It is likely that this MCA parameter will disappear before v1.3 final. = Known Issues = * The XML filter component is not complete. The current output from this component is preliminary and not real XML. A bit more work needs to be done to configure.m4 search for an appropriate XML library/link it in/use it at run time. * There are possible recursion loops in the orte_output() and orte_show_help() functions -- e.g., if RML send calls orte_output() or orte_show_help(). We have some ideas how to fix these, but figured that it was ok to commit before feature freeze with known issues. The code currently contains sub-optimal workarounds so that this will not be a problem, but it would be good to actually solve the problem rather than have hackish workarounds before v1.3 final. This commit was SVN r18434.
387 строки
13 KiB
C
387 строки
13 KiB
C
/*
|
|
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
|
|
* University Research and Technology
|
|
* Corporation. All rights reserved.
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
* of Tennessee Research Foundation. All rights
|
|
* reserved.
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
* University of Stuttgart. All rights reserved.
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
* All rights reserved.
|
|
* Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved.
|
|
* $COPYRIGHT$
|
|
*
|
|
* Additional copyrights may follow
|
|
*
|
|
* $HEADER$
|
|
*/
|
|
|
|
#include "ompi_config.h"
|
|
#include "orte/util/output.h"
|
|
#include "allocator_basic.h"
|
|
#include "ompi/constants.h"
|
|
|
|
|
|
|
|
mca_allocator_base_component_t mca_allocator_basic_component = {
|
|
|
|
/* First, the mca_base_module_t struct containing meta information
|
|
about the module itself */
|
|
|
|
{
|
|
/* Indicate that we are a allocator v1.0.0 module (which also implies a
|
|
specific MCA version) */
|
|
|
|
MCA_ALLOCATOR_BASE_VERSION_1_0_0,
|
|
|
|
"basic", /* MCA module name */
|
|
1, /* MCA module major version */
|
|
0, /* MCA module minor version */
|
|
0, /* MCA module release version */
|
|
mca_allocator_basic_component_open, /* module open */
|
|
mca_allocator_basic_component_close /* module close */
|
|
},
|
|
|
|
/* Next the MCA v1.0.0 module meta data */
|
|
|
|
{
|
|
/* The component is checkpoint ready */
|
|
MCA_BASE_METADATA_PARAM_CHECKPOINT
|
|
},
|
|
mca_allocator_basic_component_init
|
|
};
|
|
|
|
|
|
OBJ_CLASS_INSTANCE(
|
|
mca_allocator_basic_segment_t,
|
|
ompi_free_list_item_t,
|
|
NULL,
|
|
NULL);
|
|
|
|
|
|
int mca_allocator_basic_component_open(void)
|
|
{
|
|
return OMPI_SUCCESS;
|
|
}
|
|
|
|
|
|
int mca_allocator_basic_component_close(void)
|
|
{
|
|
return OMPI_SUCCESS;
|
|
}
|
|
|
|
|
|
/**
|
|
*
|
|
*/
|
|
|
|
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* mpool)
|
|
{
|
|
mca_allocator_basic_module_t *module = (mca_allocator_basic_module_t *)
|
|
malloc(sizeof(mca_allocator_basic_module_t));
|
|
if (NULL == module) {
|
|
return NULL;
|
|
}
|
|
|
|
module->super.alc_alloc = mca_allocator_basic_alloc;
|
|
module->super.alc_realloc = mca_allocator_basic_realloc;
|
|
module->super.alc_free = mca_allocator_basic_free;
|
|
module->super.alc_compact = mca_allocator_basic_compact;
|
|
module->super.alc_finalize = mca_allocator_basic_finalize;
|
|
module->super.alc_mpool = mpool;
|
|
module->seg_alloc = segment_alloc;
|
|
module->seg_free = segment_free;
|
|
OBJ_CONSTRUCT(&module->seg_list, opal_list_t);
|
|
OBJ_CONSTRUCT(&module->seg_lock, opal_mutex_t);
|
|
OBJ_CONSTRUCT(&module->seg_descriptors, ompi_free_list_t);
|
|
|
|
ompi_free_list_init_new(&module->seg_descriptors,
|
|
sizeof(mca_allocator_basic_segment_t),
|
|
CACHE_LINE_SIZE,
|
|
OBJ_CLASS(mca_allocator_basic_segment_t),
|
|
0,CACHE_LINE_SIZE,
|
|
0, /* initial size */
|
|
-1, /* maximum size */
|
|
16, /* increment to grow by */
|
|
NULL);
|
|
|
|
return &module->super;
|
|
}
|
|
|
|
/**
|
|
* Combine adjacent segments together.
|
|
*/
|
|
|
|
static void mca_allocator_basic_combine_prev(
|
|
mca_allocator_basic_module_t* module,
|
|
mca_allocator_basic_segment_t* seg)
|
|
{
|
|
opal_list_item_t* item = opal_list_get_prev(seg);
|
|
if(item != opal_list_get_begin(&module->seg_list)) {
|
|
mca_allocator_basic_segment_t *prev = (mca_allocator_basic_segment_t*)item;
|
|
if(prev->seg_addr + prev->seg_size == seg->seg_addr) {
|
|
prev->seg_size += seg->seg_size;
|
|
opal_list_remove_item(&module->seg_list, &seg->seg_item.super);
|
|
OMPI_FREE_LIST_RETURN(&module->seg_descriptors, &seg->seg_item);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void mca_allocator_basic_combine_next(
|
|
mca_allocator_basic_module_t* module,
|
|
mca_allocator_basic_segment_t* seg)
|
|
{
|
|
opal_list_item_t *item = opal_list_get_next(seg);
|
|
if(item != opal_list_get_end(&module->seg_list)) {
|
|
mca_allocator_basic_segment_t *next = (mca_allocator_basic_segment_t*)item;
|
|
if(seg->seg_addr + seg->seg_size == next->seg_addr) {
|
|
next->seg_addr = seg->seg_addr;
|
|
next->seg_size += seg->seg_size;
|
|
opal_list_remove_item(&module->seg_list, &seg->seg_item.super);
|
|
OMPI_FREE_LIST_RETURN(&module->seg_descriptors, &seg->seg_item);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Accepts a request for memory in a specific region defined by the
|
|
* mca_allocator_basic_options_t struct and returns a pointer to memory in that
|
|
* region or NULL if there was an error
|
|
*
|
|
* @param mem A pointer to the appropriate struct for the area of memory.
|
|
* @param size The size of the requested area of memory
|
|
*
|
|
* @retval Pointer to the area of memory if the allocation was successful
|
|
* @retval NULL if the allocation was unsuccessful
|
|
*/
|
|
|
|
void *mca_allocator_basic_alloc(
|
|
mca_allocator_base_module_t * base,
|
|
size_t size,
|
|
size_t align,
|
|
mca_mpool_base_registration_t** registration)
|
|
{
|
|
mca_allocator_basic_module_t* module = (mca_allocator_basic_module_t*)base;
|
|
mca_allocator_basic_segment_t* seg;
|
|
ompi_free_list_item_t* item;
|
|
unsigned char* addr;
|
|
size_t allocated_size;
|
|
OPAL_THREAD_LOCK(&module->seg_lock);
|
|
|
|
/* add the size of the header into the amount we need to request */
|
|
size += sizeof(size_t);
|
|
/* normalize size so we don't end up with seg_addr on an odd boundary */
|
|
size += sizeof(size_t) - (size & (sizeof(size_t) - 1));
|
|
/* search the list for a segment of the required size */
|
|
for(item = (ompi_free_list_item_t*) opal_list_get_first(&module->seg_list);
|
|
item != (ompi_free_list_item_t*) opal_list_get_end(&module->seg_list);
|
|
item = (ompi_free_list_item_t*) opal_list_get_next(&item->super)) {
|
|
seg = (mca_allocator_basic_segment_t*)item;
|
|
|
|
/* split the segment */
|
|
if(seg->seg_size > size) {
|
|
addr = seg->seg_addr;
|
|
seg->seg_addr += size;
|
|
seg->seg_size -= size;
|
|
OPAL_THREAD_UNLOCK(&module->seg_lock);
|
|
*(size_t*)addr = size;
|
|
return addr+sizeof(size_t);
|
|
} else if (seg->seg_size == size) {
|
|
addr = seg->seg_addr;
|
|
opal_list_remove_item(&module->seg_list, &item->super);
|
|
OMPI_FREE_LIST_RETURN(&module->seg_descriptors, item);
|
|
OPAL_THREAD_UNLOCK(&module->seg_lock);
|
|
*(size_t*)addr = size;
|
|
return addr+sizeof(size_t);
|
|
}
|
|
}
|
|
|
|
/* request additional block */
|
|
allocated_size = (unsigned char)size;
|
|
if(NULL == (addr = (unsigned char *)module->seg_alloc(module->super.alc_mpool, &allocated_size, registration))) {
|
|
OPAL_THREAD_UNLOCK(&module->seg_lock);
|
|
return NULL;
|
|
}
|
|
|
|
/* create a segment for any extra allocation */
|
|
if(allocated_size > size) {
|
|
int rc;
|
|
OMPI_FREE_LIST_GET(&module->seg_descriptors, item, rc);
|
|
if(rc != OMPI_SUCCESS) {
|
|
OPAL_THREAD_UNLOCK(&module->seg_lock);
|
|
return NULL;
|
|
}
|
|
seg = (mca_allocator_basic_segment_t*)item;
|
|
seg->seg_addr = addr + size;
|
|
seg->seg_size = allocated_size - size;
|
|
opal_list_append(&module->seg_list, &item->super);
|
|
}
|
|
|
|
*(size_t*)addr = size;
|
|
OPAL_THREAD_UNLOCK(&module->seg_lock);
|
|
return addr+sizeof(size_t);
|
|
}
|
|
|
|
|
|
/**
|
|
* Attempts to resize the passed region of memory into a larger or a smaller
|
|
* region. If it is unsuccessful, it will return NULL and the passed area of
|
|
* memory will be untouched.
|
|
*
|
|
* @param mem A pointer to the appropriate struct for the area of
|
|
* memory.
|
|
* @param size The size of the requested area of memory
|
|
* @param ptr A pointer to the region of memory to be resized
|
|
*
|
|
* @retval Pointer to the area of memory if the reallocation was successful
|
|
* @retval NULL if the allocation was unsuccessful
|
|
*
|
|
*/
|
|
|
|
void * mca_allocator_basic_realloc(
|
|
mca_allocator_base_module_t * base,
|
|
void * ptr,
|
|
size_t size,
|
|
mca_mpool_base_registration_t** registration)
|
|
{
|
|
unsigned char* addr = ((unsigned char*)ptr) - sizeof(size_t);
|
|
size_t alloc_size = *(size_t*)addr;
|
|
if(size <= alloc_size)
|
|
return ptr;
|
|
addr = (unsigned char *)mca_allocator_basic_alloc(base,size,0,registration);
|
|
if(addr == NULL)
|
|
return addr;
|
|
memcpy(addr,ptr,alloc_size);
|
|
mca_allocator_basic_free(base,ptr);
|
|
return addr;
|
|
}
|
|
|
|
|
|
/**
|
|
* Frees the passed region of memory
|
|
*
|
|
* @param mem A pointer to the appropriate struct for the area of
|
|
* memory.
|
|
* @param ptr A pointer to the region of memory to be freed
|
|
*
|
|
* @retval None
|
|
*
|
|
*/
|
|
void mca_allocator_basic_free(
|
|
mca_allocator_base_module_t * base,
|
|
void * ptr)
|
|
{
|
|
mca_allocator_basic_module_t* module = (mca_allocator_basic_module_t*)base;
|
|
mca_allocator_basic_segment_t* seg;
|
|
ompi_free_list_item_t *item;
|
|
unsigned char* addr = (unsigned char*)ptr - sizeof(size_t);
|
|
size_t size = *(size_t*)addr;
|
|
int rc;
|
|
OPAL_THREAD_LOCK(&module->seg_lock);
|
|
|
|
/* maintain the free list in sorted order by address */
|
|
for(item = (ompi_free_list_item_t*) opal_list_get_first(&module->seg_list);
|
|
item != (ompi_free_list_item_t*) opal_list_get_end(&module->seg_list);
|
|
item = (ompi_free_list_item_t*) opal_list_get_next((&item->super))) {
|
|
seg = (mca_allocator_basic_segment_t*)item;
|
|
|
|
if (seg->seg_addr < addr) {
|
|
|
|
/* can we grow the current entry */
|
|
if(seg->seg_addr + seg->seg_size == addr) {
|
|
seg->seg_size += size;
|
|
mca_allocator_basic_combine_next(module, seg);
|
|
OPAL_THREAD_UNLOCK(&module->seg_lock);
|
|
return;
|
|
}
|
|
/* otherwise continue to check next larger entry */
|
|
|
|
} else {
|
|
|
|
/* can this be combined with current entry */
|
|
if(addr + size == seg->seg_addr) {
|
|
seg->seg_addr = addr;
|
|
seg->seg_size += size;
|
|
mca_allocator_basic_combine_prev(module, seg);
|
|
OPAL_THREAD_UNLOCK(&module->seg_lock);
|
|
return;
|
|
|
|
/* insert before larger entry */
|
|
} else {
|
|
mca_allocator_basic_segment_t* new_seg;
|
|
OMPI_FREE_LIST_GET(&module->seg_descriptors, item, rc);
|
|
if(rc != OMPI_SUCCESS) {
|
|
OPAL_THREAD_UNLOCK(&module->seg_lock);
|
|
return;
|
|
}
|
|
new_seg = (
|
|
mca_allocator_basic_segment_t*)item;
|
|
new_seg->seg_addr = addr;
|
|
new_seg->seg_size = size;
|
|
opal_list_insert_pos(&module->seg_list, &seg->seg_item.super, &item->super);
|
|
OPAL_THREAD_UNLOCK(&module->seg_lock);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* append to the end of the list */
|
|
OMPI_FREE_LIST_GET(&module->seg_descriptors, item, rc);
|
|
if(rc != OMPI_SUCCESS) {
|
|
OPAL_THREAD_UNLOCK(&module->seg_lock);
|
|
return;
|
|
}
|
|
seg = (mca_allocator_basic_segment_t*)item;
|
|
seg->seg_addr = addr;
|
|
seg->seg_size = size;
|
|
opal_list_append(&module->seg_list, &item->super);
|
|
OPAL_THREAD_UNLOCK(&module->seg_lock);
|
|
}
|
|
|
|
|
|
/**
|
|
* Frees all the memory from all the basics back to the system. Note that
|
|
* this function only frees memory that was previously freed with
|
|
* mca_allocator_basic_free().
|
|
*
|
|
* @param mem A pointer to the appropriate struct for the area of
|
|
* memory.
|
|
*
|
|
* @retval None
|
|
*
|
|
*/
|
|
|
|
int mca_allocator_basic_compact(mca_allocator_base_module_t * mem)
|
|
{
|
|
return OMPI_SUCCESS;
|
|
}
|
|
|
|
/**
|
|
* Cleanup all resources held by this allocator.
|
|
*
|
|
* @param mem A pointer to the appropriate struct for the area of
|
|
* memory.
|
|
*
|
|
* @retval None
|
|
*
|
|
*/
|
|
|
|
int mca_allocator_basic_finalize(mca_allocator_base_module_t * base)
|
|
{
|
|
mca_allocator_basic_module_t* module = (mca_allocator_basic_module_t*)base;
|
|
OBJ_DESTRUCT(&module->seg_list);
|
|
OBJ_DESTRUCT(&module->seg_lock);
|
|
OBJ_DESTRUCT(&module->seg_descriptors);
|
|
free(module);
|
|
return OMPI_SUCCESS;
|
|
}
|
|
|
|
|