我将使用两组char*(或字符串)读取strtok,并且因为这两组字符是相关的,(address : command\n)所以我决定使用一个结构.
struct line* array = (struct line*)malloc(sizeof(file) * sizeof(struct line*));
Run Code Online (Sandbox Code Playgroud)
这个malloc函数的行间空间给了我一个分段错误,并想知道你是否可以告诉我一个适当的malloc空间方式.对于上下文,这是我的其余代码:
struct line
{
char* addr;
char* inst;
};
while loop{
x = strtok(line,": ");
y = strtok(NULL,"\n");
strcpy(array[i].addr,x); //assume that x and y are always 3characters
strcpy(array[i].inst,++y);
i++;
}
Run Code Online (Sandbox Code Playgroud) 假设我有一个非常大的数组,我希望用MPI(v1)发送或接收.为了索引这个数组,我使用无符号长整数.
现在,我看到的所有MPI函数调用都使用int类型作为它们的"count"参数,例如在这个例子中:
MPI_Recv(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status)
Run Code Online (Sandbox Code Playgroud)
但是,如果在我的实现中,我需要能够发送/接收大于int可以容纳的最大数量的数组?当我尝试将无符号整数提供给"count"参数时,编译器自然会给出"无效转换"错误.我想过做一个演员,但后来我担心这会缩小我的变量,所以我有点不知所措.
我如何通过MPI发送和接收此类结构?
struct controlPoint{
int hour,minute,second,x,y,z;
};
struct flight{
int flightNum, controlNum;
vector<controlPoint> point;
};
vector<flight> flights;
Run Code Online (Sandbox Code Playgroud)
示例代码将非常有用
我使用MPI在C中编写了一个程序,其中struct变量将以环形方式发送给进程,并根据从该变量接收的值,分配该特定进程的工作.
问题是我需要知道如何在MPI_Send()函数中发送struct变量,因为它在运行时给出了INVALID DATATYPE,请考虑以下示例
struct info{
int ne, n, u, v, process, min, strip, mincost, b;
} stat;
MPI_Send(&stat,sizeof(stat),sizeof(struct info),1,2,MPI_COMM_WORLD);
Run Code Online (Sandbox Code Playgroud)