コード例 #1
0
ファイル: mpiext_affinity_str.c プロジェクト: ICLDisco/ompi
/*
 * Where did OMPI bind this process? (layout string)
 */
static int get_layout_ompi_bound(char str[OMPI_AFFINITY_STRING_MAX])
{
    int ret;

    /* If OMPI did not bind, indicate that */
    if (!ompi_rte_proc_is_bound) {
        opal_string_copy(str, ompi_nobind_str, OMPI_AFFINITY_STRING_MAX);
        return OMPI_SUCCESS;
    }

    /* Find out what OMPI bound us to and prettyprint it */
    if (NULL == ompi_proc_applied_binding) {
        ret = OPAL_ERR_NOT_BOUND;
    } else {
        ret = opal_hwloc_base_cset2mapstr(str, OMPI_AFFINITY_STRING_MAX,
                                          opal_hwloc_topology,
                                          ompi_proc_applied_binding);
    }
    if (OPAL_ERR_NOT_BOUND == ret) {
        opal_string_copy(str, not_bound_str, OMPI_AFFINITY_STRING_MAX);
        ret = OMPI_SUCCESS;
    }

    return ret;
}
コード例 #2
0
void mca_fs_base_get_parent_dir ( char *filename, char **dirnamep)
{
    int err;
    char *dir = NULL, *slash;
    struct stat statbuf;

    if (strlen(filename) < 1) {
        opal_asprintf(dirnamep, ".%s", OPAL_PATH_SEP);
        return;
    }

    err = lstat(filename, &statbuf);

    if (err || (!S_ISLNK(statbuf.st_mode))) {
	/* no such file, or file is not a link; these are the "normal"
	 * cases where we can just return the parent directory.
	 */
	dir = strdup(filename);
    }
    else {
	/* filename is a symlink.  we've presumably already tried
	 * to stat it and found it to be missing (dangling link),
	 * but this code doesn't care if the target is really there
	 * or not.
	 */
	int namelen;
	char linkbuf[PATH_MAX+1];

	namelen = readlink(filename, linkbuf, PATH_MAX);
	if (namelen == -1) {
	    /* something strange has happened between the time that
	     * we determined that this was a link and the time that
	     * we attempted to read it; punt and use the old name.
	     */
	    dir = strdup(filename);
	}
	else {
	    /* successfully read the link */
	    linkbuf[namelen] = '\0'; /* readlink doesn't null terminate */
	    dir = strdup(linkbuf);
	}
    }

    slash = strrchr(dir, '/');
    if (!slash) {
        // It is guaranteed in this case that "dir" will be at least 2
        // characters long.
        opal_string_copy(dir, ".", 2);
    } else {
	if (slash == dir) {
            *(dir + 1) = '\0';
        } else {
            *slash = '\0';
        }
    }

    *dirnamep = dir;
    return;
}
コード例 #3
0
ファイル: mpiext_affinity_str.c プロジェクト: ICLDisco/ompi
/*
 * Where is this process currently bound? (layout string)
 */
static int get_layout_current_binding(char str[OMPI_AFFINITY_STRING_MAX])
{
    int ret;
    hwloc_obj_t root;
    hwloc_cpuset_t boundset, rootset;
    bool bound = false;

    /* get our root object */
    root = hwloc_get_root_obj(opal_hwloc_topology);
    rootset = root->cpuset;

    /* get our bindings */
    boundset = hwloc_bitmap_alloc();
    if (hwloc_get_cpubind(opal_hwloc_topology, boundset,
                          HWLOC_CPUBIND_PROCESS) < 0) {
        /* we are NOT bound if get_cpubind fails, nor can we be bound
           - the environment does not support it */
        bound = false;
    } else {
        /* we are bound if the two cpusets are not equal, or if there
           is only ONE PU available to us */
        if (0 != hwloc_bitmap_compare(boundset, rootset) ||
            opal_hwloc_base_single_cpu(rootset) ||
            opal_hwloc_base_single_cpu(boundset)) {
            bound = true;
        }
    }

    /* If we are not bound, indicate that */
    if (!bound) {
        strncat(str, not_bound_str, OMPI_AFFINITY_STRING_MAX - 1);
        ret = OMPI_SUCCESS;
    }

    /* If we are bound, print it out */
    else {
        ret = opal_hwloc_base_cset2mapstr(str, OMPI_AFFINITY_STRING_MAX,
                                          opal_hwloc_topology,
                                          boundset);
        if (OPAL_ERR_NOT_BOUND == ret) {
            opal_string_copy(str, not_bound_str, OMPI_AFFINITY_STRING_MAX);
            ret = OMPI_SUCCESS;
        }
    }
    hwloc_bitmap_free(boundset);

    return ret;
}
コード例 #4
0
ファイル: fd.c プロジェクト: pmix/pmix-reference-server
const char *opal_fd_get_peer_name(int fd)
{
    char *str;
    const char *ret = NULL;
    struct sockaddr sa;
    socklen_t slt = (socklen_t) sizeof(sa);

    int rc = getpeername(fd, &sa, &slt);
    if (0 != rc) {
        ret = strdup("Unknown");
        return ret;
    }

    size_t len = INET_ADDRSTRLEN;
#if OPAL_ENABLE_IPV6
    len = INET6_ADDRSTRLEN;
#endif
    str = calloc(1, len);
    if (NULL == str) {
        return NULL;
    }

    if (sa.sa_family == AF_INET) {
        struct sockaddr_in *si;
        si = (struct sockaddr_in*) &sa;
        ret = inet_ntop(AF_INET, &(si->sin_addr), str, INET_ADDRSTRLEN);
        if (NULL == ret) {
            free(str);
        }
    }
#if OPAL_ENABLE_IPV6
    else if (sa.sa_family == AF_INET6) {
        struct sockaddr_in6 *si6;
        si6 = (struct sockaddr_in6*) &sa;
        ret = inet_ntop(AF_INET6, &(si6->sin6_addr), str, INET6_ADDRSTRLEN);
        if (NULL == ret) {
            free(str);
        }
    }
#endif
    else {
        // This string is guaranteed to be <= INET_ADDRSTRLEN
        opal_string_copy(str, "Unknown", len);
        ret = str;
    }

    return ret;
}