Search code examples
capipointerslsf

How to create a correct array, that can be referenced via char** to pass parameters to LSF-API


I want to use a small C wrapper to access a so called LSF-API. LSF is the "load sharing facility" which is something like a platform to dispatch computing jobs on various machines (created by IBM).

I figured out how to do basic job submitting through populating a data structure and passing it to LSF. But when I tried to specify this data structure with some more of the defined attributes, I came to a problem which is connected to basic C issues.

I want to specify a list of hostnames, where the job should be dispatched to. According to the API, this is done with those two fields:

char **     askedHosts -> The array of names of invoker specified candidate hosts. The number of hosts is given by numAskedHosts.
int     numAskedHosts  -> length of the previous array

This char ** makes my head aching:
I assumed, that I need to create an array with my hostnames as strings, specify the amount of them and pass this somehow to my data structure:

char *myHostArray[] = {"hostname_1","hostname_2","hostname_3"};
int numberOfMyHosts = 3;
myDatastructure.askedHosts = myHostArray;
myDatastructure.numAskedHosts  = 3;

But whatever I try, it doesn't work. The depicted variant is the only one, where the compilation is at least successful and I do not get an "Segmentation fault" at runtime. But in the end the information seems not to be passed correctly since it has no effects on the job dispatching.

I guess I am messing up something with the pointers. Do you have any idea how I can pass this array correctly? I tried lots of variations but I was not successful after hours.

Do you know what I could be doing wrong here?

By the way - the API reference can be found here (I am talking about the "submit"-data structure):
https://www.ibm.com/support/knowledgecenter/en/SSWRJV_10.1.0/api_reference/index.html


Solution

  • For any optional parameter a request must tell whether this option is used or not. The options in the submit structure indeed has the flag

    #define SUB_HOST   0x04
    Flag to indicate numAskedHosts parameter has data.
    
    Equivalent to bsub -m command line option existence.
    

    You must do

        submit.options |= SUB_HOST;