/** * SELF module initialization. * * @param num_btls (OUT) Number of BTLs returned in BTL array. * @param enable_progress_threads (IN) Flag indicating whether BTL is allowed to have progress * threads * @param enable_mpi_threads (IN) Flag indicating whether BTL must support multilple * simultaneous invocations from different threads * */ staticmca_btl_base_module_t ** mca_btl_self_component_init(int *num_btls, bool enable_progress_threads, bool enable_mpi_threads);
/** * Run the hierarchy of class constructors for this object, in a * parent-first order. * * Do not use this function directly: use OBJ_CONSTRUCT() instead. * * WARNING: This implementation relies on a hardwired maximum depth of * the inheritance tree!!! * * Hardwired for fairly shallow inheritance trees * @param size Pointer to the object. */ staticinlinevoidopal_obj_run_constructors(opal_object_t *object) { opal_construct_t *cls_construct;
/** * Describes a region/segment of memory that is addressable * by an BTL. * * Note: In many cases the alloc and prepare methods of BTLs * do not return a mca_btl_base_segment_t but instead return a * subclass. Extreme care should be used when modifying * BTL segments to prevent overwriting internal BTL data. * * All BTLs MUST use base segments when calling registered * Callbacks. * * BTL MUST use mca_btl_base_segment_t or a subclass and * MUST store their segment length in btl_seg_size. BTLs * MUST specify a segment no larger than MCA_BTL_SEG_MAX_SIZE. */
structmca_btl_base_segment_t { /** Address of the memory */ opal_ptr_t seg_addr; /** Length in bytes */ uint64_t seg_len; }; typedefstructmca_btl_base_segment_tmca_btl_base_segment_t;
/** * Static initializer for a class descriptor * * @param NAME Name of class * @param PARENT Name of parent class * @param CONSTRUCTOR Pointer to constructor * @param DESTRUCTOR Pointer to destructor * * Put this in NAME.c */ #define OBJ_CLASS_INSTANCE(NAME, PARENT, CONSTRUCTOR, DESTRUCTOR) \ opal_class_t NAME##_class = {#NAME, \ OBJ_CLASS(PARENT), \ (opal_construct_t) CONSTRUCTOR, \ (opal_destruct_t) DESTRUCTOR, \ 0, \ 0, \ NULL, \ NULL, \ sizeof(NAME)}
/** * Declaration for class descriptor * * @param NAME Name of class * * Put this in NAME.h */ #define OBJ_CLASS_DECLARATION(NAME) extern opal_class_t NAME##_class
/** * Initialize a free list. * * @param free_list (IN) Free list. * @param frag_size (IN) Size of each element - allocated by malloc. * @param frag_alignment (IN) Fragment alignment. * @param frag_class (IN) opal_class_t of element - used to initialize allocated * elements. * @param payload_buffer_size (IN) Size of payload buffer - allocated from mpool. * @param payload_buffer_alignment (IN) Payload buffer alignment. * @param num_elements_to_alloc (IN) Initial number of elements to allocate. * @param max_elements_to_alloc (IN) Maximum number of elements to allocate. * @param num_elements_per_alloc (IN) Number of elements to grow by per allocation. * @param mpool (IN) Optional memory pool for allocations. * @param rcache_reg_flags (IN) Flags to pass to rcache registration function. * @param rcache (IN) Optional registration cache. * @param item_init (IN) Optional item initialization function * @param ctx (IN) Initialization function context. */
OPAL_DECLSPEC intopal_free_list_init(opal_free_list_t *free_list, size_t frag_size, size_t frag_alignment, opal_class_t *frag_class, size_t payload_buffer_size, size_t payload_buffer_alignment, int num_elements_to_alloc, int max_elements_to_alloc, int num_elements_per_alloc, structmca_mpool_base_module_t *mpool, int rcache_reg_flags, structmca_rcache_base_module_t *rcache, opal_free_list_item_init_fn_t item_init, void *ctx);
/** * PML->BTL notification of change in the process list. * PML->BTL Notification that a receive fragment has been matched. * Called for message that is send from process with the virtual * address of the shared memory segment being different than that of * the receiver. * * @param btl (IN) * @param proc (IN) * @param peer (OUT) * @return OPAL_SUCCESS or error status on failure. * */ staticintmca_btl_self_add_procs(structmca_btl_base_module_t *btl, size_t nprocs, structopal_proc_t **procs, structmca_btl_base_endpoint_t **peers, opal_bitmap_t *reachability) { for (int i = 0; i < (int) nprocs; i++) { if (0 == opal_compare_proc(procs[i]->proc_name, OPAL_PROC_MY_NAME)) { opal_bitmap_set_bit(reachability, i); /* need to return something to keep the bml from ignoring us */ peers[i] = (structmca_btl_base_endpoint_t *) 1; break; /* there will always be only one ... */ } }
return OPAL_SUCCESS; }
关键逻辑:
遍历所有传入的进程
通过 opal_compare_proc 比较进程名称与当前进程
如果是同一进程,设置位图并创建虚拟 endpoint
只会有一个进程匹配(自己)
bitmap
位图的作用: reachable 位图是一个关键的数据结构,用于:
标记可达性:每个位对应一个进程,设置为 1 表示该进程可通过此 BTL 到达
BTL 选择:上层(BML)根据位图决定使用哪些 BTL 与特定进程通信
负载均衡:当多个 BTL 都能到达同一进程时,可以进行选择
btl_del_procs - 进程删除
用于清理进程相关资源, self的实现很简单,直接返回成功,因为没有需要清理的资源。
/** * PML->BTL notification of change in the process list. * * @param btl (IN) BTL instance * @param proc (IN) Peer process * @param peer (IN) Peer addressing information. * @return Status indicating if cleanup was successful * */ staticintmca_btl_self_del_procs(structmca_btl_base_module_t *btl, size_t nprocs, structopal_proc_t **procs, structmca_btl_base_endpoint_t **peers) { return OPAL_SUCCESS; }