/* * get_proto * * returns -1 if error */ int get_proto(struct MPIR_COMMUNICATOR *comm, int src_lrank) { int rc; if (src_lrank == MPI_ANY_SOURCE) rc = (comm->vmpi_only ? mpi : unknown); else { if (src_lrank >= 0 && src_lrank < comm->np) { int src_grank = comm->lrank_to_grank[src_lrank]; struct channel_t *cp; if (!(cp = get_channel(src_grank))) { rc = -1; globus_libc_fprintf(stderr, "ERROR: get_proto: proc %d failed get_channel " "for src_grank %d\n", MPID_MyWorldRank, src_grank); print_channels(); } else if (!(cp->selected_proto)) { rc = -1; globus_libc_fprintf(stderr, "ERROR: get_proto: proc %d has NULL selected protocol " "for src_grank %d\n", MPID_MyWorldRank, src_grank); print_channels(); } else rc = (cp->selected_proto)->type; } else { rc = -1; globus_libc_fprintf(stderr, "ERROR: get_proto: src_lrank %d out of bounds for communicator " "with %d procs\n", src_lrank, comm->np); } /* endif */ } /* endif */ return rc; } /* end get_proto() */
static void perf_plugin_marker_cb( void * user_specific, globus_ftp_client_handle_t * handle, long time_stamp_int, char time_stamp_tength, int stripe_ndx, int num_stripes, globus_off_t nbytes) { globus_libc_fprintf(stderr, "perf_plugin_marker_cb\n"); globus_libc_fprintf(stderr, "time_stamp %ld.%d\n", time_stamp_int, time_stamp_tength); globus_libc_fprintf(stderr, "stripe_ndx %d\n", stripe_ndx); globus_libc_fprintf(stderr, "num_stripes %d\n", num_stripes); globus_libc_fprintf(stderr, "nbytes %" GLOBUS_OFF_T_FORMAT "\n", nbytes); }
static void perf_plugin_complete_cb( void * user_specific, globus_ftp_client_handle_t * handle, globus_bool_t success) { globus_libc_fprintf(stderr, "perf_plugin_complete_cb\n"); }
static void perf_plugin_begin_cb( void * user_specific, globus_ftp_client_handle_t * handle, const char * source_url, const char * dest_url, globus_bool_t restart) { globus_libc_fprintf(stderr, "perf_plugin_begin_cb\n"); }
int globus_l_args_create_msg( char ** msg_storage, char * message ) { if (msg_storage) *msg_storage = message; else globus_libc_fprintf( stderr, "%s", message ); return GLOBUS_SUCCESS; }
void globus_print_error( globus_result_t error_result) { globus_object_t * error_obj = NULL; char * error_string = NULL; error_obj = globus_error_get(error_result); error_string = globus_error_print_chain(error_obj); globus_libc_fprintf(stderr, "%s\n", error_string); globus_libc_free(error_string); globus_object_free(error_obj); }
void globus_version_print( const char * name, const globus_version_t * version, FILE * stream, globus_bool_t verbose) { if(name) { globus_libc_fprintf(stream, "%s: ", name); } if(version) { if(verbose) { globus_libc_fprintf( stream, "%d.%d (%lu-%d)\n", version->major, version->minor, version->timestamp, version->branch_id); } else { globus_libc_fprintf( stream, "%d.%d\n", version->major, version->minor); } } else { globus_libc_fprintf(stream, "%s", _GCSL("<no version>\n")); } }
int globus_l_args_create_error_msg( char ** error_msg, int current_argc, char * current_argv, char * error_string, const char * oneline_usage ) { char * my_error_string; char * p; int usage_len; int len; #define error_format _GCSL("\nError, argument #%d (%s) : %s\n\nSyntax : ") #define error_epilogue _GCSL("\n\nUse -help to display full usage.\n") my_error_string = (error_string) ? error_string : _GCSL("(no error message)"); len = strlen(error_format) + strlen(current_argv) + strlen(my_error_string) + strlen(oneline_usage) + strlen(error_epilogue) + 10; p = globus_l_args_malloc( char, len ); globus_assert( p ); globus_libc_sprintf( p, error_format, current_argc, current_argv, my_error_string ); usage_len = strlen( oneline_usage ); len = strlen(p); strncpy( &p[len], oneline_usage, usage_len ); sprintf( &p[len+usage_len], "%s", error_epilogue ); if (error_msg) *error_msg = p; else { globus_libc_fprintf( stderr, "%s", p ); free(p); } return GLOBUS_SUCCESS; }
void globus_i_module_dump( FILE * out_f) { globus_list_t * module_list; globus_libc_fprintf(out_f, "==========\nModule List\n----------\n"); module_list = globus_l_module_list; while(!globus_list_empty(module_list)) { globus_list_t * client_list; globus_l_module_entry_t * module_entry; module_entry = globus_list_first(module_list); module_list = globus_list_rest(module_list); globus_libc_fprintf(out_f, "%s; cnt=%d", module_entry->descriptor->module_name, module_entry->reference_count); client_list = module_entry->clients; if (!globus_list_empty(client_list)) { void * client_entry; globus_l_module_entry_t * client_module_entry; client_entry = globus_list_first(client_list); client_list = globus_list_rest(client_list); client_module_entry = globus_hashtable_lookup(&globus_l_module_table, client_entry); globus_libc_fprintf(out_f, "; clients=%s", client_module_entry->descriptor->module_name); while(!globus_list_empty(client_list)) { client_entry = globus_list_first(client_list); client_list = globus_list_rest(client_list); client_module_entry = globus_hashtable_lookup(&globus_l_module_table, client_entry); globus_libc_fprintf(out_f, ",%s", client_module_entry->descriptor->module_name); } } globus_libc_fprintf(out_f, "\n"); } globus_libc_fprintf(out_f, "==========\n"); }
/* * MPID_Pack_size * * NOTE: MPID_Msg_pack_t msgact ignored for reasons stated at top of file * * NOTE: there's no way for me to report an error condition. * where's the *error_code arg? * in case of an error, i will return pass 0 and print an error * message to stdout. */ void MPID_Pack_size(int count, struct MPIR_DATATYPE *datatype, MPID_Msg_pack_t msgact, /* ignored */ int *size) { int tmp_size; tmp_size = local_size(count, datatype); if (tmp_size < 0) { globus_libc_fprintf(stderr, "ERROR: MPID_Pack_size could not calculate pack size, returning 0\n"); *size = 0; } /* endif */ *size = tmp_size + sizeof(unsigned char); }
/* * MPID_Get_count * * return into 'count' the number of COMPLETE 'datatype' in the buffer * described by 'status' * * there are a couple of potential erroneuous/weird scenarios: * - 'datatype' is a non-empty (i.e., sizeof(datatype)>0) complex type * AND there is not enough data to completely fill all the datatypes * (last one only partially filled). * in this case *count = MPI_UNDEFINED * - sizeof(datatype) == 0, in this case the "correct" count cannot be * determined ... *count could be set to anything from 0-infinity, * the MPI standard does not discuss this case (at least i couldn't * find anything on it) so we look at the number of bytes in the * data buffer, * - if sizeof(databuff) == 0 then we take a guess and set *count = 0 * and hope that's what the user expected. * - if sizeof(databuff) > 0 then things are REALLY messed up and we * give up by setting *count = MPI_UNDEFINED. */ int MPID_Get_count(MPI_Status *status, MPI_Datatype datatype, int *count) { struct MPIR_DATATYPE *dtype_ptr = (struct MPIR_DATATYPE *) MPIR_GET_DTYPE_PTR(datatype); # if defined(VMPI) if (STATUS_INFO_IS_COUNT_VMPI(*status)) { MPID_Type_validate_vmpi(dtype_ptr); return vmpi_error_to_mpich_error( mp_get_count(STATUS_INFO_GET_VMPI_PTR(*status), dtype_ptr->vmpi_type, count)); } else # endif /* defined(VMPI) */ if (status->count == 0) { /* * this is more than just an optimization. if the app calls * MPI_{Recv,Irecv} from MPI_PROC_NULL, then the MPICH code * simply sets status->count=0 and does NOT call our * MPID_{Recv,Irecv}, and therefore we don't get to set * status->private_count to ISLOCAL or ISDATAORIGIN. * without that setting, the rest of the code in this * function will fail. */ *count = 0; } else if (dtype_ptr->size <= 0) { /* * this is weird ... we're being asked to count how many * 0-byte data elements are in a non-empty buffer ... the * "correct" answer is anywhere from 0-inifinite ... (probably * _countably_ infinite, if that helps ;-)) */ *count = MPI_UNDEFINED; } else { int unit_size; if (STATUS_INFO_IS_COUNT_LOCAL(*status)) { /* status->count is the number of bytes in local format */ unit_size = dtype_ptr->size; } else if (STATUS_INFO_IS_COUNT_REMOTE(*status)) { /* status->count is the number of bytes in remote format */ unit_size = remote_size(1, dtype_ptr, STATUS_INFO_GET_FORMAT(*status)); if (unit_size <= 0) { globus_libc_fprintf(stderr, "ERROR: MPID_Get_count: datatype %d local size %d, " "remote size %d\n", dtype_ptr->dte_type, dtype_ptr->size, unit_size); return MPI_ERR_INTERN; } /* endif */ } else { globus_libc_fprintf(stderr, "ERROR: MPID_Get_count: could not interpret " "status->private_count %d\n", status->extra[0]); return MPI_ERR_INTERN; } /* endif */ if (status->count % unit_size) /* uh-oh! last element is only partially filled */ *count = MPI_UNDEFINED; else *count = status->count / unit_size; } /* endif */ return MPI_SUCCESS; } /* end MPID_Get_count() */
/* * mpich_globus2_pack_data() * * the destination buffer is decribed by 'dest_buff_start' (beginning of dest * buff, but not necessarily where to begin packing), 'maxcount' (size in bytes * of dest buff), and 'position' (diplacement, in bytes, into 'dest_buff_start' * where to start packing). we must update 'position' as we pack more data. * * NOTE: struct MPIR_COMMUNICATOR *comm, int partner, and * MPID_Msg_pack_t msgact are ignored for reasons stated * at top of file. * MPID_Msgrep_t msgrep is ignored during packing for the globus2 * device because of our reader-makes-right model, i.e. we always * pack/send data in its native format. * * NOTE: there is one more datatype found in datatype.h ... MPIR_FORT_INT * it has been explained to me by bill that we do not have to * support an explicit case for that type because it is a * synonym for one of the other types we already have a case * statement for (which type it is a synonym for is architecture * dependent and determined during mpich configuration). * * NICK: because this is an MPID routine as opposed to a MPI routine, * it is assumed that there is enough room ('maxcount' bytes) * to pack the data into 'src'. we do not bother checking * that here, and therefore we essentially ignore maxcount also * .... maybe that's an assumption we're not allowed to make? */ void mpich_globus2_pack_data( void * src, /* src args */ int count, struct MPIR_DATATYPE * datatype, void * dest_buff_start, /* dest args */ int * position, int * error_code) { globus_byte_t *dest_before_put, *dst; *error_code = 0; if (count == 0 || datatype->size == 0) return ; dst = dest_before_put = ((globus_byte_t *) dest_buff_start) + *position; switch (datatype->dte_type) { case MPIR_CHAR: globus_dc_put_char(&dst,(char *)src,count); break; case MPIR_UCHAR: globus_dc_put_u_char(&dst,(u_char *)src,count); break; case MPIR_PACKED: /* THIS MUST BE A MEMCPY, i.e., NOT CONVERTED */ memcpy((void *) dst, src, count); dst += count; break; case MPIR_BYTE: /* THIS MUST BE A MEMCPY, i.e., NOT CONVERTED */ memcpy((void *) dst, src, count); dst += count; break; case MPIR_SHORT: globus_dc_put_short(&dst,(short *)src,count); break; case MPIR_USHORT: globus_dc_put_u_short(&dst,(u_short *)src,count); break; case MPIR_LOGICAL: /* 'logical' in FORTRAN is always same as 'int' */ case MPIR_INT: globus_dc_put_int(&dst,(int *)src,count); break; case MPIR_UINT: globus_dc_put_u_int(&dst,(u_int *)src,count); break; case MPIR_LONG: globus_dc_put_long(&dst,(long *)src,count); break; case MPIR_LONGLONGINT: globus_dc_put_long_long(&dst,(long long *)src,count); break; case MPIR_ULONG: globus_dc_put_u_long(&dst,(u_long *)src,count); break; case MPIR_FLOAT: globus_dc_put_float(&dst,(float *)src,count); break; case MPIR_DOUBLE: globus_dc_put_double(&dst,(double *)src,count); break; case MPIR_LONGDOUBLE: *error_code = MPI_ERR_TYPE; break; case MPIR_UB: case MPIR_LB: break; case MPIR_COMPLEX: globus_dc_put_float(&dst,(float *)src,2*count); break; case MPIR_DOUBLE_COMPLEX: globus_dc_put_double(&dst,(double *)src,2*count); break; /* * rest are complex data types requiring special care * by decomposing down to their basic types */ case MPIR_CONTIG: mpich_globus2_pack_data(src, count * datatype->count, datatype->old_type, dest_buff_start, position, error_code); break; case MPIR_VECTOR: case MPIR_HVECTOR: { globus_byte_t *tmp = (globus_byte_t *) src; int i, j; for (i = 0; *error_code == 0 && i < count; i++) { src = (void *) tmp; for (j = 0; *error_code == 0 && j < datatype->count; j++) { mpich_globus2_pack_data(src, datatype->blocklen, datatype->old_type, dest_buff_start, position, error_code); src = (void *) (((globus_byte_t *) src) + datatype->stride); } /* endfor */ tmp += datatype->extent; } /* endfor */ } break; case MPIR_INDEXED: case MPIR_HINDEXED: { void *tmp; int i, j; for (i = 0; *error_code == 0 && i < count; i++) { for (j = 0; *error_code == 0 && j < datatype->count; j++) { tmp = (void *) (((char *) src) + datatype->indices[j]); mpich_globus2_pack_data(tmp, datatype->blocklens[j], datatype->old_type, dest_buff_start, position, error_code); } /* endfor */ src = (void *) (((globus_byte_t *) src) + datatype->extent); } /* endfor */ } break; case MPIR_STRUCT: { void *tmp; int i, j; for (i = 0; *error_code == 0 && i < count; i++) { for (j = 0; *error_code == 0 && j < datatype->count; j++) { tmp = (void *) (((char *) src) + datatype->indices[j]); mpich_globus2_pack_data(tmp, datatype->blocklens[j], datatype->old_types[j], dest_buff_start, position, error_code); } /* endfor */ src = (void *) (((globus_byte_t *) src) + datatype->extent); } /* endfor */ } break; default: globus_libc_fprintf(stderr, "ERROR: MPID_Pack: encountered unrecognizable MPIR type %d\n", datatype->dte_type); *error_code = MPI_ERR_INTERN; return; break; } /* end switch() */ /* updating 'position' for basic data types */ if (*error_code == 0) { switch (datatype->dte_type) { case MPIR_CHAR: case MPIR_UCHAR: case MPIR_PACKED: case MPIR_BYTE: case MPIR_SHORT: case MPIR_USHORT: case MPIR_LOGICAL: case MPIR_INT: case MPIR_UINT: case MPIR_LONG: case MPIR_LONGLONGINT: case MPIR_ULONG: case MPIR_FLOAT: case MPIR_DOUBLE: case MPIR_LONGDOUBLE: case MPIR_COMPLEX: case MPIR_DOUBLE_COMPLEX: (*position) += (dst - dest_before_put); break; default: break; } /* end switch() */ } /* endif */ } /* end mpich_globus2_pack_data() */
/* * local_size * * return -1 when there's problems * * NOTE: there is one more datatype found in datatype.h ... MPIR_FORT_INT * it has been explained to me by bill that we do not have to * support an explicit case for that type because it is a * synonym for one of the other types we already have a case * statement for (which type it is a synonym for is architecture * dependent and determined during mpich configuration). * */ int local_size(int count, struct MPIR_DATATYPE *datatype) { int rc; if (count < 0) { globus_libc_fprintf(stderr, "ERROR: local_size: passed count %d .... must be >= 0\n", count); return -1; } /* endif */ switch(datatype->dte_type) { case MPIR_CHAR: rc = globus_dc_sizeof_char(count); break; case MPIR_UCHAR: rc = globus_dc_sizeof_u_char(count); break; /* MPIR_PACKED are always raw bytes and are never converted */ case MPIR_PACKED: rc = count; break; case MPIR_BYTE: rc = count ; break; case MPIR_SHORT: rc = globus_dc_sizeof_short(count); break; case MPIR_USHORT: rc = globus_dc_sizeof_u_short(count); break; case MPIR_LOGICAL: /* 'logical' in FORTRAN is always same as 'int' */ case MPIR_INT: rc = globus_dc_sizeof_int(count); break; case MPIR_UINT: rc = globus_dc_sizeof_u_int(count); break; case MPIR_LONG: rc = globus_dc_sizeof_long(count); break; case MPIR_LONGLONGINT: rc = globus_dc_sizeof_long_long(count); break; case MPIR_ULONG: rc = globus_dc_sizeof_u_long(count); break; case MPIR_FLOAT: rc = globus_dc_sizeof_float(count); break; case MPIR_DOUBLE: rc = globus_dc_sizeof_double(count); break; case MPIR_LONGDOUBLE: /* not supported by Globus */ rc = 0; break; case MPIR_UB: case MPIR_LB: rc = 0; break; case MPIR_COMPLEX: rc = globus_dc_sizeof_float(2*count); break; case MPIR_DOUBLE_COMPLEX: rc = globus_dc_sizeof_double(2*count); break; case MPIR_CONTIG: rc = local_size(count*datatype->count, datatype->old_type); break; case MPIR_VECTOR: case MPIR_HVECTOR: { int tmp = local_size(datatype->blocklen, datatype->old_type); rc = (tmp == -1 ? -1 : tmp*count*datatype->count); } break; case MPIR_INDEXED: case MPIR_HINDEXED: { int i, tmp, tmp2; for (rc = tmp = tmp2 = i = 0; tmp2 != -1 && i < datatype->count; i++) { tmp2 = local_size(datatype->blocklens[i], datatype->old_type); if (tmp2 == -1) tmp = -1; else tmp += tmp2; } /* endfor */ if (tmp != -1) rc = tmp*count; else rc = -1; } break; case MPIR_STRUCT: { int i, tmp, tmp2; for (rc = tmp = tmp2 = i = 0; tmp2 != -1 && i < datatype->count; i++) { tmp2 = local_size(datatype->blocklens[i], datatype->old_types[i]); if (tmp2 == -1) tmp = -1; else tmp += tmp2; } /* endfor */ if (tmp != -1) rc = tmp*count; else rc = -1; } break; default: globus_libc_fprintf(stderr, "ERROR: local_size: encountered unrecognizable MPIR type %d\n", datatype->dte_type); rc = -1; break; } /* end switch */ return rc; } /* end local_size() */
/* * mpich_globus2_unpack_data * * the source buffer is decribed by 'src_buff_start' (beginning of src buff, * but not necessarily where to begin unpacking from), 'maxcount' (size in * bytes), 'msgrep' (dataorigin format), and 'in_position' (diplacement, * in bytes, into 'dest_buff_start' from where to start unpacking). * similarly, the dest buffer is described by 'dest_buff_start' and * 'out_position'. we must update 'in_position' and 'out_position' * as we unpack the data. * * NICK: it is assumed that there is enouch data in the source to * completely fill the dest buff as described. futher, any * 'extra' data left in the src after filling the dest is ignored. * .... maybe that's an assumption we're not allowed to make? * * NOTE: there is one more datatype found in datatype.h ... MPIR_FORT_INT * it has been explained to me by bill that we do not have to * support an explicit case for that type because it is a * synonym for one of the other types we already have a case * statement for (which type it is a synonym for is architecture * dependent and determined during mpich configuration). */ void mpich_globus2_unpack_data( void * src_buff_start, /* src args */ int * in_position, int src_format, void * dest_buff_start, /* dest args */ int count, struct MPIR_DATATYPE * datatype, int * out_position, int * error_code) { *error_code = 0; switch (datatype->dte_type) { case MPIR_CHAR: case MPIR_UCHAR: case MPIR_PACKED: case MPIR_BYTE: case MPIR_SHORT: case MPIR_USHORT: case MPIR_LOGICAL: case MPIR_INT: case MPIR_UINT: case MPIR_LONG: case MPIR_LONGLONGINT: case MPIR_ULONG: case MPIR_FLOAT: case MPIR_DOUBLE: case MPIR_UB: case MPIR_LB: case MPIR_COMPLEX: case MPIR_DOUBLE_COMPLEX: { globus_byte_t *src_after_unpack = ((globus_byte_t *)src_buff_start) + *in_position; globus_byte_t *src_before_unpack = src_after_unpack; int nbytes_rcvd = 0; if (extract_complete_from_buff(&src_after_unpack, ((globus_byte_t *) dest_buff_start) + *out_position, count, datatype, src_format, &nbytes_rcvd)) { *error_code = MPI_ERR_INTERN; } else { (*in_position) += (src_after_unpack - src_before_unpack); (*out_position) += nbytes_rcvd; } /* endif */ } break; case MPIR_LONGDOUBLE: *error_code = MPI_ERR_TYPE; break; /* * rest are complex data types requiring special care * by decomposing down to their basic types */ case MPIR_CONTIG: mpich_globus2_unpack_data(src_buff_start, in_position, src_format, dest_buff_start, count * datatype->count, datatype->old_type, out_position, error_code); break; case MPIR_VECTOR: case MPIR_HVECTOR: { globus_byte_t *tmp = (globus_byte_t *) dest_buff_start; int i, j, tmp_int; for (i = 0; *error_code == 0 && i < count; i++) { dest_buff_start = (void *) tmp; for (j = 0; *error_code == 0 && j < datatype->count; j++) { tmp_int = 0; mpich_globus2_unpack_data(src_buff_start, in_position, src_format, dest_buff_start, datatype->blocklen, datatype->old_type, &tmp_int, error_code); *out_position += tmp_int; dest_buff_start = (void *) (((globus_byte_t *) dest_buff_start) + datatype->stride); } /* endfor */ tmp += datatype->extent; } /* endfor */ } break; case MPIR_INDEXED: case MPIR_HINDEXED: { globus_byte_t *tmp; int i, j, tmp_int; for (i = 0; *error_code == 0 && i < count; i++) { for (j = 0; *error_code == 0 && j < datatype->count; j++) { tmp_int = 0; tmp = (globus_byte_t *) dest_buff_start + datatype->indices[j]; mpich_globus2_unpack_data(src_buff_start, in_position, src_format, tmp, datatype->blocklens[j], datatype->old_type, &tmp_int, error_code); *out_position += tmp_int; } /* endfor */ dest_buff_start = (void *) (((globus_byte_t *) dest_buff_start) + datatype->extent); } /* endfor */ } break; case MPIR_STRUCT: { globus_byte_t *tmp; int i, j, tmp_int; for (i = 0; *error_code == 0 && i < count; i++) { for (j = 0; *error_code == 0 && j < datatype->count; j++) { tmp_int = 0; tmp = (globus_byte_t *) dest_buff_start + datatype->indices[j]; mpich_globus2_unpack_data(src_buff_start, in_position, src_format, tmp, datatype->blocklens[j], datatype->old_types[j], &tmp_int, error_code); *out_position += tmp_int; } /* endfor */ dest_buff_start = (void *) (((globus_byte_t *) dest_buff_start) + datatype->extent); } /* endfor */ } break; default: globus_libc_fprintf(stderr, "ERROR: MPID_Unpack: encountered unrecognizable MPIR type %d\n", datatype->dte_type); *error_code = MPI_ERR_INTERN; break; } /* end switch() */ }
static int get_elements_from_partial(int req_nelem, struct MPIR_DATATYPE *datatype, int format, int *nbytes_remaining, int *elements, globus_bool_t *done) { int rc = 0; switch (datatype->dte_type) { case MPIR_CHAR: case MPIR_UCHAR: case MPIR_PACKED: case MPIR_BYTE: case MPIR_SHORT: case MPIR_USHORT: case MPIR_LOGICAL: case MPIR_INT: case MPIR_UINT: case MPIR_LONG: case MPIR_LONGLONGINT: case MPIR_ULONG: case MPIR_FLOAT: case MPIR_DOUBLE: case MPIR_COMPLEX: case MPIR_DOUBLE_COMPLEX: { /* basic datatypes */ int unit_size; int inbuf_nelem; int nelem; if ((unit_size = remote_size(1, datatype, format)) <= 0) { globus_libc_fprintf(stderr, "ERROR: get_elements_from_partial: datatype %d " "format %d got invalid remote unit size %d\n", datatype->dte_type, format, unit_size); return 1; } /* endif */ inbuf_nelem = (*nbytes_remaining) / unit_size; if ((nelem = (req_nelem<inbuf_nelem ? req_nelem : inbuf_nelem)) != 0) { (*nbytes_remaining) -= (nelem * unit_size); (*elements) += nelem; } /* endif */ if (nelem < req_nelem) *done = GLOBUS_TRUE; } break; case MPIR_LONGDOUBLE: /* not supported */ break; case MPIR_UB: /* MPIR_UB and MPIR_LB are 0-byte datatypes */ case MPIR_LB: break; /* * rest are complex data types requiring special care * by decomposing down to their basic types */ case MPIR_CONTIG: rc = get_elements_from_partial(req_nelem * datatype->count, datatype->old_type, format, nbytes_remaining, elements, done); break; case MPIR_VECTOR: case MPIR_HVECTOR: { int i, j; for (i = 0; !rc && !(*done) && i < req_nelem; i ++) for (j = 0; !rc && !(*done) && j < datatype->count; j ++) rc = get_elements_from_partial(datatype->blocklen, datatype->old_type, format, nbytes_remaining, elements, done); } break; case MPIR_INDEXED: case MPIR_HINDEXED: { int i, j; for (i = 0; !rc && !(*done) && i < req_nelem; i ++) for (j = 0; !rc && !(*done) && j < datatype->count; j ++) rc = get_elements_from_partial(datatype->blocklens[j], datatype->old_types[j], format, nbytes_remaining, elements, done); } break; case MPIR_STRUCT: { int i, j; for (i = 0; !rc && !(*done) && i < req_nelem; i ++) for (j = 0; !rc && !(*done) && j < datatype->count; j ++) rc = get_elements_from_partial(datatype->blocklens[j], datatype->old_types[j], format, nbytes_remaining, elements, done); } break; default: globus_libc_fprintf(stderr, "ERROR: get_elements_from_partial: encountered unrecognizable " "datatype %d\n", datatype->dte_type); return 1; break; } /* end switch() */ return rc; } /* end get_elements_from_partial() */
/* * MPID_Get_elements * * return into 'elements' the number of basic datatypes that are in * the buffer described by status. for complex 'datatype' this requires * counting how many basic datatypes there are, which includes counting those * basic datatypes that appear in a potentially partially-filled last datatype. * * there is a potentially weird scenario: * - sizeof(datatype) == 0, in this case the "correct" count cannot be * determined ... *count could be set to anything from 0-infinity, * the MPI standard does not discuss this case (at least i couldn't * find anything on it) so we look at the number of bytes in the * data buffer, * - if sizeof(databuff) == 0 then we take a guess and set * *elements = 0, rc = MPI_SUCCESS, and hope that's what * the user expected. * - if sizeof(databuff) > 0 then things are REALLY messed up and we * give up by simply returning rc = MPI_ERR_INTERN. */ int MPID_Get_elements(MPI_Status *status, MPI_Datatype datatype, int *elements) { struct MPIR_DATATYPE *dtype_ptr = (struct MPIR_DATATYPE *) MPIR_GET_DTYPE_PTR(datatype); # if defined(VMPI) if (STATUS_INFO_IS_COUNT_VMPI(*status)) { MPID_Type_validate_vmpi(dtype_ptr); return vmpi_error_to_mpich_error( mp_get_elements(STATUS_INFO_GET_VMPI_PTR(*status), dtype_ptr->vmpi_type, elements)); } else # endif /* defined(VMPI) */ if (status->count == 0) { /* * this is more than just an optimization. if the app calls * MPI_{Recv,Irecv} from MPI_PROC_NULL, then the MPICH code * simply sets status->count=0 and does NOT call our * MPID_{Recv,Irecv}, and therefore we don't get to set * status->private_count to ISLOCAL or ISDATAORIGIN. * without that setting, the rest of the code in this * function will fail. */ *elements = 0; } else if (dtype_ptr->size <= 0) { /* * this is weird ... we're being asked to count how many * 0-byte data elements are in a non-empty buffer ... the * "correct" answer is anywhere from 0-inifinite ... (probably * _countably_ infinite, if that helps ;-)) */ return MPI_ERR_INTERN; } else { int unit_size; int format; int nbytes_remaining; if (STATUS_INFO_IS_COUNT_LOCAL(*status)) { /* status->count is the number of bytes in local format */ format = GLOBUS_DC_FORMAT_LOCAL; unit_size = dtype_ptr->size; } else if (STATUS_INFO_IS_COUNT_REMOTE(*status)) { /* status->count is the number of bytes in remote format */ format = STATUS_INFO_GET_FORMAT(*status); if ((unit_size = remote_size(1, dtype_ptr, format)) <= 0) { globus_libc_fprintf(stderr, "ERROR: MPID_Get_elements: datatype %d local size %d, " "remote size %d\n", dtype_ptr->dte_type, dtype_ptr->size, unit_size); return MPI_ERR_INTERN; } /* endif */ } else { globus_libc_fprintf(stderr, "ERROR: MPID_Get_elements: could not interpret " "status->private_count %d\n", status->extra[0]); return MPI_ERR_INTERN; } /* endif */ /* count the basic datatypes in 'full' ones */ *elements = (status->count / unit_size) * dtype_ptr->elements; if ((nbytes_remaining = status->count-(*elements * unit_size)) > 0) { /* last element is only partially filled ... need */ /* to count the basic datatypes in that one too */ globus_bool_t done = GLOBUS_FALSE; if (get_elements_from_partial(1, dtype_ptr, format, &nbytes_remaining, elements, &done)) /* something bad happened */ return MPI_ERR_INTERN; else if (nbytes_remaining > 0) { /* * after counting all the basic element types we can, * decrementing nbytes_remaining along the way, there * are STILL residual bytes left over that could not be * accounted for based on the 'datatype' we were passed. * still going to return *elements and MPI_SUCCESS, but * printing warning message (stderr) here. */ globus_libc_fprintf(stderr, "WARNING: MPID_Get_elements counted all the basic " "datatypes it could based\n"); globus_libc_fprintf(stderr, " the specified datatype, but still had %d " "residual bytes that\n", nbytes_remaining); globus_libc_fprintf(stderr, " could not be accounted for.\n"); } /* endif */ } /* endif */ } /* endif */ return MPI_SUCCESS; } /* end MPID_Get_elements() */
int main( int argc, char * argv[]) { globus_io_handle_t listener; globus_io_handle_t server_handle; globus_io_handle_t client_handle; globus_io_attr_t attr; unsigned short port = 0; globus_result_t result; globus_io_secure_authorization_data_t auth_data; globus_l_io_authorization_test_monitor_t monitor; char greeting[] = "Hello, my friend."; char reply_buffer[256]; globus_size_t written; globus_size_t read_amt; LTDL_SET_PRELOADED_SYMBOLS(); globus_module_activate(GLOBUS_COMMON_MODULE); globus_module_activate(GLOBUS_IO_MODULE); /* Initialize monitor */ globus_mutex_init(&monitor.mutex, GLOBUS_NULL); globus_cond_init(&monitor.cond, GLOBUS_NULL); monitor.connected = GLOBUS_FALSE; /* Prepare attributes */ globus_io_secure_authorization_data_initialize(&auth_data); globus_io_tcpattr_init(&attr); globus_io_attr_set_secure_authentication_mode( &attr, GLOBUS_IO_SECURE_AUTHENTICATION_MODE_GSSAPI, GSS_C_NO_CREDENTIAL); if(argc >= 2) { if(! strcasecmp(argv[1], "self")) { globus_io_attr_set_secure_authorization_mode( &attr, GLOBUS_IO_SECURE_AUTHORIZATION_MODE_SELF, &auth_data); } else if(argc > 2 && ! strcasecmp(argv[1], "identity") ) { globus_io_secure_authorization_data_set_identity(&auth_data, argv[2]); globus_io_attr_set_secure_authorization_mode( &attr, GLOBUS_IO_SECURE_AUTHORIZATION_MODE_IDENTITY, &auth_data); } else if(! strcasecmp(argv[1], "callback")) { globus_io_secure_authorization_data_set_callback( &auth_data, globus_l_io_authorization_test_callback, GLOBUS_NULL); globus_io_attr_set_secure_authorization_mode( &attr, GLOBUS_IO_SECURE_AUTHORIZATION_MODE_CALLBACK, &auth_data); } else if(! strcasecmp(argv[1], "-callback")) { globus_io_secure_authorization_data_set_callback( &auth_data, globus_l_io_authorization_test_callback, (void *) 0x1); globus_io_attr_set_secure_authorization_mode( &attr, GLOBUS_IO_SECURE_AUTHORIZATION_MODE_CALLBACK, &auth_data); } else { goto no_authorization_mode; } } else { goto no_authorization_mode; } result = globus_io_tcp_create_listener( &port, -1, &attr, &listener); if(result != GLOBUS_SUCCESS) { char *msg = globus_error_print_friendly(globus_error_peek(result)); globus_libc_fprintf(stderr, "# Could not create listener: %s\n", msg); free(msg); goto error_exit; } result = globus_io_tcp_register_connect( "localhost", port, &attr, globus_l_io_authorization_test_connect_callback, &monitor, &client_handle); if(result != GLOBUS_SUCCESS) { globus_libc_printf("# Could not register connect\n"); goto error_exit; } result = globus_io_tcp_listen(&listener); if(result != GLOBUS_SUCCESS) { globus_libc_printf("# Could not listen for connections\n"); goto error_exit; } result = globus_io_tcp_accept(&listener, &attr, &server_handle); if(result != GLOBUS_SUCCESS) { if(strcasecmp(argv[1], "-callback") == 0) { globus_module_deactivate_all(); exit(0); } else { globus_libc_printf("# Could not accept connection\n"); goto error_exit; } } globus_mutex_lock(&monitor.mutex); while(! monitor.connected) { globus_cond_wait(&monitor.cond, &monitor.mutex); } result = globus_io_close(&listener); if(result != GLOBUS_SUCCESS) { globus_libc_printf("# Could not close listener\n"); goto error_exit; } result = globus_io_write(&server_handle, greeting, sizeof(greeting), &written); if(result != GLOBUS_SUCCESS) { globus_libc_printf("# Could not write greeting\n"); goto error_exit; } result = globus_io_close(&server_handle); if(result != GLOBUS_SUCCESS) { globus_libc_printf("# Could not close server\n"); goto error_exit; } result = globus_io_read(&client_handle, reply_buffer, sizeof(reply_buffer), sizeof(reply_buffer), &read_amt); if(result != GLOBUS_SUCCESS) { globus_object_t * err; err = globus_error_get(result); if(! globus_io_eof(err)) { globus_libc_printf("# Could not read greeting\n"); goto error_exit; } } result = globus_io_close(&client_handle); if(result != GLOBUS_SUCCESS) { globus_libc_printf("# Could not close client\n"); goto error_exit; } if(!memcmp(greeting, reply_buffer, sizeof(greeting)) == 0) { result = GLOBUS_FAILURE; goto error_exit; } globus_module_deactivate_all(); exit(0); no_authorization_mode: globus_libc_printf( "Usage: %s AUTHORIZATION\n" " AUTHORIZATION is one of\n" " self use Globus I/O's self-authorization mode\n" " identity \"subject\" use Globus I/O's subject-based authorization\n" " callback use Globus I/O's callback authorization\n" " -callback use Globus I/O's callback authorization with\n" " a failure callback\n", argv[0]); error_exit: globus_module_deactivate_all(); exit(1); }
int main(int argc, char *argv[]) { int rc = 1; monitor_t monitor; char * rsl; if (argc < 4 || (!globus_l_get_mode(&monitor, argv[2])) || ((monitor.timeout = atoi(argv[3])) < 0)) { globus_libc_fprintf(stderr, "Usage: %s RM-CONTACT MODE SAVE_STATE TIMEOUT\n" " RM-CONTACT: resource manager contact\n" " MODE: no-commit|no-commit-end|commit|late-commit-end\n" " TIMEOUT: two-phase timeout in seconds\n", argv[0]); goto error_exit; } rc = globus_module_activate(GLOBUS_GRAM_CLIENT_MODULE); if (rc != GLOBUS_SUCCESS) { globus_libc_fprintf(stderr, "failure activating GLOBUS_GRAM_CLIENT_MODULE: %s\n", globus_gram_client_error_string(rc)); goto error_exit; } rsl = globus_common_create_string(format, monitor.timeout); if (rsl == NULL) { globus_libc_fprintf(stderr, "failure allocating rsl string\n"); goto deactivate_exit; } globus_mutex_init(&monitor.mutex, NULL); globus_cond_init(&monitor.cond, NULL); monitor.job_contact = NULL; monitor.callback_contact = NULL; rc = globus_gram_client_callback_allow( globus_l_state_callback, &monitor, &monitor.callback_contact); if (rc != GLOBUS_SUCCESS || monitor.callback_contact == NULL) { globus_libc_fprintf(stderr, "failure allowing callbacks\n"); rc = -1; goto destroy_monitor_exit; } globus_mutex_lock(&monitor.mutex); rc = globus_gram_client_job_request( argv[1], rsl, GLOBUS_GRAM_PROTOCOL_JOB_STATE_ALL, monitor.callback_contact, &monitor.job_contact); if (monitor.job_contact != NULL) { globus_libc_printf("%s\n", monitor.job_contact); } if (rc != GLOBUS_GRAM_PROTOCOL_ERROR_WAITING_FOR_COMMIT) { if (rc == GLOBUS_SUCCESS) { globus_libc_fprintf(stderr, "job manager did not return " "GLOBUS_GRAM_PROTOCOL_ERROR_COMMIT_TIMED_OUT\n"); rc = -1; } else { globus_libc_fprintf(stderr, "failure submitting job request [%d]: %s\n", rc, globus_gram_client_error_string(rc)); } goto disallow_exit; } rc = 0; if (monitor.mode == no_commit) { goto disallow_exit; } rc = globus_gram_client_job_signal( monitor.job_contact, GLOBUS_GRAM_PROTOCOL_JOB_SIGNAL_COMMIT_REQUEST, NULL, &monitor.job_status, &monitor.failure_code); if (rc != GLOBUS_SUCCESS) { globus_libc_fprintf(stderr, "failure sending commit signal: %s\n", globus_gram_client_error_string(rc)); goto disallow_exit; } while (monitor.job_status != GLOBUS_GRAM_PROTOCOL_JOB_STATE_DONE && monitor.job_status != GLOBUS_GRAM_PROTOCOL_JOB_STATE_FAILED) { globus_cond_wait(&monitor.cond, &monitor.mutex); } if (monitor.mode == no_commit_end) { rc = 0; goto disallow_exit; } else if (monitor.mode == late_commit_end) { rc = 0; sleep(monitor.timeout + 1); } rc = globus_gram_client_job_signal( monitor.job_contact, GLOBUS_GRAM_PROTOCOL_JOB_SIGNAL_COMMIT_END, NULL, &monitor.job_status, &monitor.failure_code); if (rc != GLOBUS_SUCCESS) { globus_libc_fprintf(stderr, "failure sending commit end signal: %s\n", globus_gram_client_error_string(rc)); goto disallow_exit; } disallow_exit: if (monitor.job_contact != NULL) { globus_gram_client_job_contact_free(monitor.job_contact); } globus_mutex_unlock(&monitor.mutex); globus_gram_client_callback_disallow(monitor.callback_contact); destroy_monitor_exit: if (monitor.callback_contact != NULL) { free(monitor.callback_contact); } globus_mutex_destroy(&monitor.mutex); globus_cond_destroy(&monitor.cond); free(rsl); deactivate_exit: globus_module_deactivate_all(); error_exit: return rc; }