Choose ib_dev when using rdma cm api

I use rdma_cm api to write app, but i have two devices. How can i set what device to use, for example mlx4_0 or mlx4_1. I can use rdma_get_device function, but when i set rdma_cm_id->verbs context that i whan, i get segfault. And rdma_create_id chooses first found? Can you explain or give some examples, because examples from google give me simple examples, i think for single device. ​if i set two ip on ipoib devices, it does not help.

Did you consult the our RDMA Programing UM? Section 8 Programming examples using RDMA verbs, rdma_get_devices?