Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ultrafilter
Aug 23, 2007

It's okay if you have any questions.



Have you looked into spatial databases? I don't know much about those except that they exist, but it's possible that everything you want to do is implemented as standard queries.

Adbot
ADBOT LOVES YOU

ExcessBLarg!
Sep 1, 2001

cheetah7071 posted:

e: this approach also has the advantage that its trivial to restart a run that failed because windows decided to update or something
I was going to say, instead of being too concerned about "worrying" memory conditions, maybe implement a checkpointing system so you can restart if you do run out of memory, or for any other reason like the user straight up quitting.

nielsm
Jun 1, 2009



ultrafilter posted:

Have you looked into spatial databases? I don't know much about those except that they exist, but it's possible that everything you want to do is implemented as standard queries.

I think the worry is that the dataset is already large, and it needs to fit and be processed on a single regular high-end laptop, maybe with an external USB drive. That's why the data is compressed.

ExcessBLarg! posted:

I was going to say, instead of being too concerned about "worrying" memory conditions, maybe implement a checkpointing system so you can restart if you do run out of memory, or for any other reason like the user straight up quitting.

Reminds me of the people in the Windows 10 thread crying about it forcing a reboot to install updates, while their scientific processing software is running and the multi-day job is not checkpointed or restartable.

cheetah7071
Oct 20, 2010

honk honk
College Slice

nielsm posted:

I think the worry is that the dataset is already large, and it needs to fit and be processed on a single regular high-end laptop, maybe with an external USB drive. That's why the data is compressed.

this, basically. Holding the entire dataset in memory--or even restructuring the entire dataset into more convenient files--is a non-starter for how the intended audience will be actually using the data

ExcessBLarg! posted:

I was going to say, instead of being too concerned about "worrying" memory conditions, maybe implement a checkpointing system so you can restart if you do run out of memory, or for any other reason like the user straight up quitting.

that makes a lot of sense

cheetah7071
Oct 20, 2010

honk honk
College Slice

nielsm posted:

Reminds me of the people in the Windows 10 thread crying about it forcing a reboot to install updates, while their scientific processing software is running and the multi-day job is not checkpointed or restartable.

I'm in this picture lol

the whole purpose of this project is to take the tiny niche of a niche of a niche that I'm an expert in and make something more user-friendly than the current options that exist. The current options are either 20 years old with command line interfaces and memory management designed for 32-bit systems that take forever to run, or an R package which is honestly excellent but requires the user to know R when a lot of them aren't too solid on what a computer is

e: I know it sounds ironic for someone asking basic questions like "why is my code crashing when I manually call a destructor???" to have an ambition like this but seriously the number of people with venn diagram of knowledge needed to even make the attempt is probably <20 worldwide and I'm tired of the tools I have to work with and the inability for anybody who doesn't live in that venn diagram to get anything done without asking me for help

cheetah7071 fucked around with this message at 18:24 on May 15, 2022

cheetah7071
Oct 20, 2010

honk honk
College Slice
I want to thank this thread for poking deeper instead of just answering my super-specific questions because while researching quantile approximation algorithms I realized that the fact that my data is numeric and I have known-ahead-of-time upper and lower bounds means I can just store all my data as a histogram instead of as the raw data and get really good estimates of basically every statistic at like 1% of the memory usage

Computer viking
May 30, 2011
Now with less breakage.

Also, and this is not useful in any way -

quote:

The desired output is a new grid laid over the same area, with a much finer resolution, where the value in each gridcell is stuff like "the mean z value of all points whose x/y fall within this cell". Basic statistics like that. The resolution of these grids is such that they easily fit in memory on an average machine, but might still be up into the tens of millions of values in a large dataset. In the normal case, where the input files are non-overlapping, the majority of gridcells (~90% of them or so) will only need data from one file. Along the edge between files, they'll need two, and the rare gridcells at the intersection will need four.

Am I just missing something, or do you mean a coarser resolution?

cheetah7071
Oct 20, 2010

honk honk
College Slice

Computer viking posted:

Also, and this is not useful in any way -

Am I just missing something, or do you mean a coarser resolution?

No I meant finer than the resolution of the input files. The input files cover areas a few square km; I want metrics calculated every few dozen meters.

Computer viking
May 30, 2011
Now with less breakage.

cheetah7071 posted:

No I meant finer than the resolution of the input files. The input files cover areas a few square km; I want metrics calculated every few dozen meters.

Right - it sounded like you were summarizing to a lower resolution. I take it this is more akin to a 2D interpolation?

If so: a) I have zero useful insight and b) that does sound sort of everything-intensive.

yippee cahier
Mar 28, 2005

Does anyone know of a project with a GNU linker script for a Cortex M system that’s run completely in RAM (alongside linux)? This would be more for a reference to make sure I’m doing things properly.

Our vendor has given us a demo project with a proprietary toolchain and IDE, but switching to ARM’s would be a lot more flexible. Of course, translating their linker script directly is a no go because it’s linked with their startup code and C library which is being replaced with newlib.

The other core will copy a firmware image to RAM and release the M core from reset. I think I’ll just take a standard flash linker script and omit both the .data relocation and NOLOAD from the .bss section so memory should be good to go when Reset_Handler is called. Sound right?

edit: Nevermind, this system is structured the same as a flash based microcontroller, only the "flash" area is actually SRAM. I'll do it the normal way and avoid any possible headaches about rules for the different memory regions.

yippee cahier fucked around with this message at 18:48 on May 23, 2022

Foxfire_
Nov 8, 2010

You should be able to just get rid of all the AT> directives so load and run addresses are the same, then change startup assembly to not do any copying or zeroing bss

sailormoon
Jun 28, 2014

fighting evil by moonlight
winning love by daylight


Is nix the best "package manager" in 2022?

Trying not to go crazy with setting up a personal project and forgot how bad C++ was without everything being managed by bazel.

Also curious about build systems 👀 it looks like zig is one of the better compilers for cross platform stuffs at the moment.

I just want to gently caress around with SDL2 and WebAssembky but almost want to switch languages because of the headache :(

sailormoon fucked around with this message at 05:41 on May 25, 2022

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today
nix is idiosyncratic and best practices for it are in flux, but it's really good at its job. Highly recommended for managing build environment and dependencies, if you only need Linux.

Ralith fucked around with this message at 23:15 on May 25, 2022

cheetah7071
Oct 20, 2010

honk honk
College Slice
I'm bumping into a truly bizarre error

I have code that is working perfectly well in my old tests, which were written in the visual studio testing framework. I wrote them in that framework mostly out of inertia because that was the framework I learned when I first learned C++, because it was built in and simple. But it's kind of clunky and not OS-portable, so I finally got off my rear end and started porting my tests to Boost's framework. I'm just providing the context here to say that this is already tested code and I'm not writing new tests for new code.

The truly bizarre error is that I have a bunch of constants in one of my headers like

code:
namespace linearUnitDefs {
	const Unit meter{ "metre",1.,unitType::linear,unitStatus::setByUser };
	const Unit foot{ "foot",0.3048,unitType::linear,unitStatus::setByUser };
	const Unit surveyFoot{ "US survey foot",0.30480060960122,unitType::linear,unitStatus::setByUser };
	const Unit unkLinear{ "unknown",1.,unitType::linear,unitStatus::unknown };
}
Where Unit is just a simple struct wrapping around that information. In my previous tests, and in my actual exe, they're behaving perfectly reasonably and can be passed around and do the expected thing. But, bizarrely, in Boost's tests, any time these constants are referenced, they end up seemingly fully zeroed out--not even default constructed, because the default constructor is very similar to the unkLinear constant. It's like every member of them was reset to its default constructor. So the string I'm using to store the name turns into an empty string, the number that stores the conversion to meters becomes 0, etc. I can literally do

code:
std::cout << linearUnitDefs::meter.name
and it prints "metre" in my actual app but prints an empty string in Boost's tests

Are Boost's tests just like, cursed? Do constants just not work in them for some reason???? It's not even like some secret corner of the code can be redefining them before my cout, because they're declared const.

I'm probably gonna just switch to Google tests because I've barely even started porting my tests over so it's a pretty low sunk cost, and I don't really care to try to deal with inscrutable nonsense on already-working code. But I'd at least be interested to hear why this bizarre behavior is even happening, if anyone knows.

cheetah7071 fucked around with this message at 04:02 on May 27, 2022

Foxfire_
Nov 8, 2010

Is the thing that sees then as uninitialized memory also called from a global constructor? And is that constructor in another translation unit?

Cause the order that those run is arbitrary and will change with different compilers or filesystems, but everything will work fine if it happens to be the order you intended

cheetah7071
Oct 20, 2010

honk honk
College Slice
Ah, that is it! I was lazily defining my test variables directly as global variables in the test .cpp because the version of Boost's macros I was using wants them to be directly passed in as macro parameters, so it's kind of inevitable you'll be defining them as global constructors. I never really use global variables except for tiny little independent constants in my actual app, so that explains why everything is working normally there. To be honest, it would be a pain in the rear end to fix this problem, which suggests looking into Google tests, anyways

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
You might be able to use constexpr to force the initialization to happen before global constructors kick in.

Xarn
Jun 26, 2015
Yep, that looks very constexprable.

Wipfmetz
Oct 12, 2007

Sitzen ein oder mehrere Wipfe in einer Lore, so kann man sie ueber den Rand der Lore hinausschauen sehen.
I recently stumbled over a kinda-similar problem, where I've defined some quick & dirty non-const-globals.

https://www.learncpp.com/cpp-tutorial/why-non-const-global-variables-are-evil/ explains it all.

Edit:
I'm not positioning this for a long-term-solution or a solution for constants.

Wipfmetz fucked around with this message at 05:56 on May 30, 2022

cheetah7071
Oct 20, 2010

honk honk
College Slice
Google tests seem a lot easier to use than Boost tests anyways, and completely sidestep the issue

The thing that caused me to want to use global variables in Boost tests was the ability to do automatic loops over test cases. Like if you were testing your addition function on a custom class, this code works:

code:
namespace bdata = boost::unit_test::data;

std::vector<MyClass> lhs = {-1,0,1,2,3};
std::vector<MyClass> rhs = {-3,4,0,-1,2};
std::vector<int> expected = {-4,4,1,1,5};

BOOST_DATA_TEST_CASE(addTest, bdata::make(lhs)^bdata::make(rhs)^bdata::make(expected), a, b, exp) {
	MyClass c = a+b;
	BOOST_TEST(c.getInt()==exp);
}
The ^ operator there is zipping the three vectors together, and in the macro it's running a loop assigning the elements of each one to a, b, and exp. This is a fairly compact way to write a lot of tests but like. You can also just write a loop? It's not that hard, and only adds a few extra lines, and is much more readable to boot.

I sort of got the impression from the documentation that Boost's testing library is powerful to the point of being impenetrable. I'm much happier having switched to Google tests even setting aside the issue of global variables. The functionality is fairly basic but it doesn't need to be complicated, it needs to be understandable. And the output to the console when something goes wrong is very well-formatted, which is a big bonus.

Probably not news to anyone who's been using C++ longer than I have, but it's a big improvement over visual studio's native unit tests, which are kind of awful and I picked them more or less at random when I first started with the language, and then kept using them out of inertia.

cheetah7071 fucked around with this message at 06:26 on May 30, 2022

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Wipfmetz posted:

I recently stumbled over a kinda-similar problem, where I've defined some quick & dirty non-const-globals.

https://www.learncpp.com/cpp-tutorial/why-non-const-global-variables-are-evil/ explains it all.

Edit:
I'm not positioning this for a long-term-solution or a solution for constants.
Article weirdly doesn't mention the static lazy-initialized global solution that solves for initialization order.

code:
const Whatever& x() {
  static const Whatever value = doWhateverComplicatedInitializationYouWant();
  return value;
}
The main downsides being "it's a bit verbose" and "you have to reference your variable as a function call rather than as a value". (And possible issues with destruction order if you're weirdly doing this with something that has entangled destructors.)

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
I want to do something with dates and times but I don't know where to start.

I want to create yearly "events" for which I can specify a month/day/time that they start. Then I need to be able to tell where those events are in relation to the current time. I might even want to do more advanced things like "the first day of spring."

Which library should I be using? Can std::chrono help me do this? I can't really understand anything in there. I'm using C++17.

I may just wind up manually entering timestamps for the events for the next 10 years or something. But if there's a library out there that can make this easy then I'd like to do things properly.

Nalin
Sep 29, 2007

Hair Elf

baby puzzle posted:

I want to do something with dates and times but I don't know where to start.

I want to create yearly "events" for which I can specify a month/day/time that they start. Then I need to be able to tell where those events are in relation to the current time. I might even want to do more advanced things like "the first day of spring."

Which library should I be using? Can std::chrono help me do this? I can't really understand anything in there. I'm using C++17.

I may just wind up manually entering timestamps for the events for the next 10 years or something. But if there's a library out there that can make this easy then I'd like to do things properly.

Honestly, std::chrono is not going to help you unless you move to C++20 as all of the important calendar functions you want weren't implemented until then. With C++17, all you can really do is grab time points from your system clock and calculate durations between two times.

The calendar functionality is what you need to create time points based on dates. It lets you construct time points based off month/day/year, the second Tuesday of a month, etc, and even has some basic functionality like figuring out what day of the week your time is on. However, it cannot do anything more advanced like finding out what day spring starts. But it could do everything else you need.

But again, C++20 required. And sorry, I don't know of any date library that would help you off the top of my head. And sadly cppreference.com doesn't list any either.

Phobeste
Apr 9, 2006

never, like, count out Touchdown Tom, man

baby puzzle posted:

I want to do something with dates and times but I don't know where to start.

I want to create yearly "events" for which I can specify a month/day/time that they start. Then I need to be able to tell where those events are in relation to the current time. I might even want to do more advanced things like "the first day of spring."

Which library should I be using? Can std::chrono help me do this? I can't really understand anything in there. I'm using C++17.

I may just wind up manually entering timestamps for the events for the next 10 years or something. But if there's a library out there that can make this easy then I'd like to do things properly.

You might want to check out boost's calendar for this, I think that would work.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
The c++20 date stuff is available as a standalone library.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
You can use the C time facilities like struct tm.

Foxfire_
Nov 8, 2010

Predicting the equinoxes is complicated and involves big tables of observed solar data anyway, so you're probably best off just tabling that

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
Thanks for the answers.

Foxfire_ posted:

Predicting the equinoxes is complicated and involves big tables of observed solar data anyway, so you're probably best off just tabling that

You are right about that. I'll just google a few years worth and then wonder why the events stopped happening all of the sudden when the table runs out.

Computer viking
May 30, 2011
Now with less breakage.

baby puzzle posted:

Thanks for the answers.

You are right about that. I'll just google a few years worth and then wonder why the events stopped happening all of the sudden when the table runs out.

I believe the traditional approach is to include a local copy of a library that completely dwarfs your own code, running a complicated set of calculations on every startup.

Sweeper
Nov 29, 2007
The Joe Buck of Posting
Dinosaur Gum

baby puzzle posted:

Thanks for the answers.

You are right about that. I'll just google a few years worth and then wonder why the events stopped happening all of the sudden when the table runs out.

Makes me wonder if you could get a support contract which involved doing this every two years

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Just pull in all of ICU as a dep for your 100kb library it's nbd.

Volguus
Mar 3, 2009
I have a little problem with a program of mine that's built with vcpkg's libraries, uses boost's ASIO and includes openssl.
Two days ago Fedora updated the crypto-policies packages and among other changes they have updated /usr/share/crypto-policies/DEFAULT/opensslcnf.txt to include the following thing:

pre:
[openssl_init]
alg_section = evp_properties

[evp_properties]
rh-allow-sha1-signatures = yes
Now my program crashes when it tries to create an SSL context with:

pre:
terminate called after throwing an instance of 'boost::wrapexcept<boost::system::system_error>'
  what():  context: unknown option (digital envelope routines) [asio.ssl:50331817]
Removing rh-allow-sha1-signatures = yes from opensslcnf.txt allows the program to start and work. It certainly looks like it just doesn't know about the rh-allow-sha1-signatures option, which looks like a RedHat specific thing.
Is there a way to tell ASIO's SSL context to ignore unknown options in the policy files? What could I do? submit a patch to openssl? vcpkg? Is it a version mismatch? Should I use just the openssl libraries installed on the OS?

nielsm
Jun 1, 2009



Use the OS-supplied libraries, or configure your own library so it doesn't read a config file possibly written for a different, incompatible version.

Volguus
Mar 3, 2009
Hmm, I was afraid of that. Ended up copying the openssl port from the root of vcpkg into my project's dir, told vcpkg that that's where I have overlays and changed it to always set no-autoload-config option. I have no idea if this improves or decreases security, but at least doesn't load potential broken (for this release) configuration files.

Falcorum
Oct 21, 2010
Does anyone know of a place with actual documentation/information on generating LLVM debug information using its C++ API? I've been writing my own language and while I'm used to LLVM's poor documentation, information on generating debug info seems mostly non-existent besides its doxygen and a single, very brief section in the Kaleidoscope tutorial.

I'm guessing I'll end up having to go through the LLVM sources to figure out how that stuff actually works, but figured I'd ask first. :v:

Falcorum fucked around with this message at 23:23 on Jun 13, 2022

BattleMaster
Aug 14, 2000

I have a question for testing a program written in C in Linux that uses system calls.

I have this fully working loop that forks off a bunch of worker processes from the parent:

code:
	for (id = 0; id < args.numWorkers; id++)
	{
		pid = fork();
	
		if (pid == (pid_t)0) // Worker
		{
			break;
		}
		else if (pid < (pid_t)0) // Error
		{
			perror("fork");
			printf("Can't create worker process #%i\n", id);
			
			// Kill processes that have already been spawned
			int numProcesses = id;
			
			for (id = 0; id < numProcesses; id++)
			{
				if (!kill(processTable[id].pid, SIGKILL))
				{
					perror("fork");
				}
			}
			
			exit(EXIT_FAILURE);
		}
		else // Parent
		{
			printf("Spawned worker process %i (PID %i)\n", id, pid);
			
			// Store mapping between our internal id and the process id
			processTable[id].pid = pid;
		}
	}
However, I don't actually know if the part that responds to fork failing actually works because it shouldn't fail under normal conditions - something really messed up needs to be happening for the system to hit maximum processes or not have tens of kilobytes of RAM to spare.

Is there any way I can inject an arbitrary failure into a system call, like saying that after x forks I want the next one to fail?

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

BattleMaster posted:

I have a question for testing a program written in C in Linux that uses system calls.

I have this fully working loop that forks off a bunch of worker processes from the parent:

code:
	for (id = 0; id < args.numWorkers; id++)
	{
		pid = fork();
	
		if (pid == (pid_t)0) // Worker
		{
			break;
		}
		else if (pid < (pid_t)0) // Error
		{
			perror("fork");
			printf("Can't create worker process #%i\n", id);
			
			// Kill processes that have already been spawned
			int numProcesses = id;
			
			for (id = 0; id < numProcesses; id++)
			{
				if (!kill(processTable[id].pid, SIGKILL))
				{
					perror("fork");
				}
			}
			
			exit(EXIT_FAILURE);
		}
		else // Parent
		{
			printf("Spawned worker process %i (PID %i)\n", id, pid);
			
			// Store mapping between our internal id and the process id
			processTable[id].pid = pid;
		}
	}
However, I don't actually know if the part that responds to fork failing actually works because it shouldn't fail under normal conditions - something really messed up needs to be happening for the system to hit maximum processes or not have tens of kilobytes of RAM to spare.

Is there any way I can inject an arbitrary failure into a system call, like saying that after x forks I want the next one to fail?

Easiest thing is to have your test code set numWorkers to intmax.

more falafel please
Feb 26, 2005

forums poster

On Linux you could use ulimit to cap the number of processes for a user.

BattleMaster
Aug 14, 2000

leper khan posted:

Easiest thing is to have your test code set numWorkers to intmax.

Thanks! I had a bad feeling about spawning so many processes that each peg a full core but it doesn't take long to fail and it showed me that I messed up a couple of things in the kill loop :toot:



Though if there are ways to make system calls arbitrarily fail that could still help me in the future.

Adbot
ADBOT LOVES YOU

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
You can strace a program and inject failures into specific system calls using -e inject.

Not really something you can easily fit into a unit testing framework or similar, but if you're after once-off testing then it seems like exactly what you want.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply