如何创建一个正确的数组,可以通过 char** 引用以将参数传递给 LSF-API
How to create a correct array, that can be referenced via char** to pass parameters to LSF-API
我想使用一个小的 C 包装器来访问所谓的 LSF-API。 LSF 是 "load sharing facility",类似于在各种机器(由 IBM 创建)上调度计算作业的平台。
我想出了如何通过填充数据结构并将其传递给 LSF 来完成基本的提交工作。但是当我试图用更多定义的属性来指定这个数据结构时,我遇到了一个与基本 C 问题相关的问题。
我想指定一个主机名列表,作业应分派到该列表。
根据 API,这是用这两个字段完成的:
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
这个char **
让我头疼:
我假设,我需要用我的主机名作为字符串创建一个数组,指定它们的数量并将其以某种方式传递给我的数据结构:
char *myHostArray[] = {"hostname_1","hostname_2","hostname_3"};
int numberOfMyHosts = 3;
myDatastructure.askedHosts = myHostArray;
myDatastructure.numAskedHosts = 3;
但无论我尝试什么,它都不起作用。所描述的变体是唯一一个,编译至少是成功的,我在运行时没有得到 "Segmentation fault"。
但最终信息似乎没有正确传递,因为它对作业调度没有影响。
我想我把指针弄乱了。
你知道我如何正确传递这个数组吗?我尝试了很多变体,但几个小时后我没有成功。
你知道我在这里可能做错了什么吗?
顺便说一下 - API 参考可以在这里找到(我说的是 "submit"-数据结构):
https://www.ibm.com/support/knowledgecenter/en/SSWRJV_10.1.0/api_reference/index.html
希望这个例子对你有所帮助:
#include <stdio.h>
void func(char **args, int n) {
int i;
for (i=0; i<n; i++)
printf("%s\n", args[i]);
}
int main(void) {
char *askedHosts[] = {"hostname_1","hostname_2","hostname_3"};
int numOfHosts = 3;
func(askedHosts, numOfHosts);
}
对于任何可选参数,请求必须说明是否使用此选项。 submit
结构中的options
确实有标志
#define SUB_HOST 0x04
Flag to indicate numAskedHosts parameter has data.
Equivalent to bsub -m command line option existence.
你必须做
submit.options |= SUB_HOST;
我想使用一个小的 C 包装器来访问所谓的 LSF-API。 LSF 是 "load sharing facility",类似于在各种机器(由 IBM 创建)上调度计算作业的平台。
我想出了如何通过填充数据结构并将其传递给 LSF 来完成基本的提交工作。但是当我试图用更多定义的属性来指定这个数据结构时,我遇到了一个与基本 C 问题相关的问题。
我想指定一个主机名列表,作业应分派到该列表。 根据 API,这是用这两个字段完成的:
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
这个char **
让我头疼:
我假设,我需要用我的主机名作为字符串创建一个数组,指定它们的数量并将其以某种方式传递给我的数据结构:
char *myHostArray[] = {"hostname_1","hostname_2","hostname_3"};
int numberOfMyHosts = 3;
myDatastructure.askedHosts = myHostArray;
myDatastructure.numAskedHosts = 3;
但无论我尝试什么,它都不起作用。所描述的变体是唯一一个,编译至少是成功的,我在运行时没有得到 "Segmentation fault"。 但最终信息似乎没有正确传递,因为它对作业调度没有影响。
我想我把指针弄乱了。 你知道我如何正确传递这个数组吗?我尝试了很多变体,但几个小时后我没有成功。
你知道我在这里可能做错了什么吗?
顺便说一下 - API 参考可以在这里找到(我说的是 "submit"-数据结构):
https://www.ibm.com/support/knowledgecenter/en/SSWRJV_10.1.0/api_reference/index.html
希望这个例子对你有所帮助:
#include <stdio.h>
void func(char **args, int n) {
int i;
for (i=0; i<n; i++)
printf("%s\n", args[i]);
}
int main(void) {
char *askedHosts[] = {"hostname_1","hostname_2","hostname_3"};
int numOfHosts = 3;
func(askedHosts, numOfHosts);
}
对于任何可选参数,请求必须说明是否使用此选项。 submit
结构中的options
确实有标志
#define SUB_HOST 0x04
Flag to indicate numAskedHosts parameter has data.
Equivalent to bsub -m command line option existence.
你必须做
submit.options |= SUB_HOST;