Exemple #1
0
int psmx_fabric(struct fi_fabric_attr *attr,
		struct fid_fabric **fabric, void *context)
{
	struct psmx_fid_fabric *fabric_priv;
	int ret;

	FI_INFO(&psmx_prov, FI_LOG_CORE, "\n");

	if (strcmp(attr->name, PSMX_FABRIC_NAME))
		return -FI_ENODATA;

	if (psmx_active_fabric) {
		psmx_fabric_acquire(psmx_active_fabric);
		*fabric = &psmx_active_fabric->util_fabric.fabric_fid;
		return 0;
	}

	fabric_priv = calloc(1, sizeof(*fabric_priv));
	if (!fabric_priv)
		return -FI_ENOMEM;

	ret = ofi_fabric_init(&psmx_prov, &psmx_fabric_attr, attr,
			     &fabric_priv->util_fabric, context,
			     FI_MATCH_EXACT);
	if (ret) {
		FI_INFO(&psmx_prov, FI_LOG_CORE, "ofi_fabric_init returns %d\n", ret);
		free(fabric_priv);
		return ret;
	}

	/* fclass & context initialzied in ofi_fabric_init */
	fabric_priv->util_fabric.fabric_fid.fid.ops = &psmx_fabric_fi_ops;
	fabric_priv->util_fabric.fabric_fid.ops = &psmx_fabric_ops;

	psmx_get_uuid(fabric_priv->uuid);

	if (psmx_env.name_server) {
		ret = pthread_create(&fabric_priv->name_server_thread, NULL,
				     psmx_name_server, (void *)fabric_priv);
		if (ret) {
			FI_INFO(&psmx_prov, FI_LOG_CORE, "pthread_create returns %d\n", ret);
			/* use the main thread's ID as invalid value for the new thread */
			fabric_priv->name_server_thread = pthread_self();
		}
	}

	psmx_query_mpi();

	/* take the reference to count for multiple fabric open calls */
	psmx_fabric_acquire(fabric_priv);

	*fabric = &fabric_priv->util_fabric.fabric_fid;
	psmx_active_fabric = fabric_priv;

	return 0;
}
Exemple #2
0
static int psmx_fabric(struct fi_fabric_attr *attr,
		       struct fid_fabric **fabric, void *context)
{
	struct psmx_fid_fabric *fabric_priv;
	pthread_t thread;
	pthread_attr_t thread_attr;

	FI_INFO(&psmx_prov, FI_LOG_CORE, "\n");

	if (strncmp(attr->name, PSMX_FABRIC_NAME, PSMX_FABRIC_NAME_LEN))
		return -FI_ENODATA;

	if (psmx_active_fabric) {
		psmx_active_fabric->refcnt++;
		*fabric = &psmx_active_fabric->fabric;
		return 0;
	}

	fabric_priv = calloc(1, sizeof(*fabric_priv));
	if (!fabric_priv)
		return -FI_ENOMEM;

	fabric_priv->fabric.fid.fclass = FI_CLASS_FABRIC;
	fabric_priv->fabric.fid.context = context;
	fabric_priv->fabric.fid.ops = &psmx_fabric_fi_ops;
	fabric_priv->fabric.ops = &psmx_fabric_ops;

	psmx_get_uuid(fabric_priv->uuid);

	if (psmx_env.name_server) {
		pthread_attr_init(&thread_attr);
		pthread_attr_setdetachstate(&thread_attr,PTHREAD_CREATE_DETACHED);
		pthread_create(&thread, &thread_attr, psmx_name_server, (void *)fabric_priv);
	}

	psmx_query_mpi();

	fabric_priv->refcnt = 1;
	*fabric = &fabric_priv->fabric;
	return 0;
}