struct

Using MPI_Type_create_struct() to transfer structs containing dynamic arrays in C

梦想与她 提交于 2019-12-23 05:39:17
问题 Overview: I am testing that the data type I create using MPI_Type_create_struct() is correct and hence sends the correct values. I am having trouble with getting the values stored in the arrays to transfer onto the other processors. I think this is likely a problem with the memory addresses of the arrays in each struct bound and the offsets stored in the array indices[] used to create the data type mpibound. Problem: I'm working on a program using MPI and my end goal is to use MPI_Gatherv()

Initialization of an array of structs in C++

坚强是说给别人听的谎言 提交于 2019-12-23 05:35:09
问题 If I have a struct like below: typedef struct MyStruct { char **str; int num; } MyStruct; Is there a way for me to initialize an array of this structures. Perhaps like below: const MyStruct MY_STRUCTS[] = { { {"Hello"}, 1 }, { {"my other string"}, 3 }, }; Ultimately I would like to have a constantly declared array of structs inside a C++ class. How can this be done? Is it possible to have a privately declared member that is pre-initialized? 回答1: Sure, you'd write it like this: #include

Why output of the below code is -1 and -2? [duplicate]

怎甘沉沦 提交于 2019-12-23 05:26:43
问题 This question already has answers here : Struct variable doesn't changed by assignment (3 answers) Closed 2 years ago . Why output of the below code is -1 and -2, It should be 1 and 2, Right? Also on a 64 bit server size of the below structure is 4 Bytes, It should be 8 Bytes right? #include<stdio.h> struct st { int a:1; int b:2; }; main() { struct st obj={1,2}; printf("a = %d\nb = %d\n",obj.a,obj.b); printf("Size of struct = %d\n",sizeof(obj)); } 回答1: Compile with all the warnings enabled,

MPI_Allgather and dynamic struct

半世苍凉 提交于 2019-12-23 05:18:28
问题 I want to send a array of structure with the MPI_Allgather() but my structure has a dynamic array: typedef struct { float a; int* b; } structure_t; My structure is initialised the following way: structure_t *resultat = (structure_t*) malloc( sizeof( structure_t ) + n * sizeof( int ) ); But how can I send my structure with MPI_Allgather ? How can I create the two (send and receive) arrays? 来源: https://stackoverflow.com/questions/9866096/mpi-allgather-and-dynamic-struct

Jsonify map of structs in Go

巧了我就是萌 提交于 2019-12-23 05:08:09
问题 So right now I have a struct for client connections which looks as following type ClientConn struct { uuid string websocket *websocket.Conn ip net.Addr longitude float64 latitude float64 } and I've also got a map of ClientConn as following var clientList = make(map[string]*ClientConn) so I add a new ClientConn on each connection to the clientList but what I'm trying to do is jsonify the clientList and obtain an array of ClientConn with its values and not just keys. If I do json.Marshal

Unnesting structs in BigQuery

可紊 提交于 2019-12-23 04:54:28
问题 What is the correct way to flatten a struct of two arrays in BigQuery? I have a dataset like the one pictured here (the struct.destination and struct.visitors arrays are ordered - i.e. the visitor counts correspond specifically to the destinations in the same row): I want to reorganize the data so that I have a total visitor count for each unique combination of origins and destinations. Ideally, the end result will look like this: I tried using UNNEST twice in a row - once on struct

How to Search Struct (Swift)

你离开我真会死。 提交于 2019-12-23 04:35:57
问题 I am changing my 2 arrays... var title = ["Title 1", "Title 2", "Title 3"] var artist = ["Artist 1", "Artist 2", "Artist 3"] ...to a struct struct Song { var title: String var artist: String } var songs: [Song] = [ Song(title: "Title 1", artist "Artist 1"), Song(title: "Title 2", artist "Artist 2"), Song(title: "Title 3", artist "Artist 3"), ] I set up my UITableView so that the title of the cell equals songs[indexPath.row].title , and the subtitle of the cell equals songs[indexPath.row]

C++ Return Array of Structs

烂漫一生 提交于 2019-12-23 04:12:46
问题 Ok so I have a struct listed as such: typedef struct name { string thing1; string thing2; int thing3; int thing4; }; I use a function that runs through data and assigns everything into an array of structs establish the inside struct array. name structname; function runs fine and assigns everything inside correctly... structname[i].thing1 structname[i].thing2 etc. will cout fine inside the function My question is how do I assign the function to return this array of structs? I can't seem to use

C++ Return Array of Structs

眉间皱痕 提交于 2019-12-23 04:12:09
问题 Ok so I have a struct listed as such: typedef struct name { string thing1; string thing2; int thing3; int thing4; }; I use a function that runs through data and assigns everything into an array of structs establish the inside struct array. name structname; function runs fine and assigns everything inside correctly... structname[i].thing1 structname[i].thing2 etc. will cout fine inside the function My question is how do I assign the function to return this array of structs? I can't seem to use

JNA: how to deal with unkown structs?

人走茶凉 提交于 2019-12-23 04:10:52
问题 If I'm not mistaken, a JNA Structure builds the struct by relying on the public fields of its corresponding Java class, which should extend Structure . My problem is that I need to pass a struct whose declaration is not known beforehand (let's say it's known at runtime). I just have a list of Object s, which the C library expects as a (reference to a) struct. Can I still use the Structure class or must I build a Memory object by hand, dealing with sizes, alignments/packing myself? For example