sstsimulator / sst-core

SST Structural Simulation Toolkit Parallel Discrete Event Core and Services
http://www.sst-simulator.org
Other
129 stars 88 forks source link

Output to File Output Location Causes Segmentation Fault #1099

Open deanchester opened 3 months ago

deanchester commented 3 months ago

I need to write some data to a file per component within SST and reading the docs the Output Class can handle writing to files.

In the constructor of hr_router I constructed the Output object:

    std::string filename("rtr-"); 
    filename = filename+ std::to_string(id) +".csv";
    bufferOccupanciesOutput = Output("", 0, 0, Output::FILE, filename);

And then I write to the output object with code like so:

            bufferOccupanciesOutput.output("%" PRIu64 ",", getCurrentSimTimeNano()); 
            for(size_t i = 0; i < (num_ports*num_vcs); ++i)
            {
                bufferOccupanciesOutput.output("%d,", output_queue_lengths[i]); 
            }
            bufferOccupanciesOutput.output("\n"); 

The segmentation fault is:

[MACHINE:12586] *** Process received signal ***
[MACHINE:12586] Signal: Segmentation fault: 11 (11)
[MACHINE:12586] Signal code: Address not mapped (1)
[MACHINE:12586] Failing at address: 0x68
[MACHINE:12586] [ 0] 0   libsystem_platform.dylib            0x00007ff819f78dfd _sigtramp + 29
[MACHINE:12586] [ 1] 0   ???                                 0x00000001096da000 0x0 + 4453146624
[MACHINE:12586] [ 2] 0   libsystem_c.dylib                   0x00007ff819e65ea5 vfprintf + 24
[MACHINE:12586] [ 3] 0   sstsim.x                            0x00000001092a5840 _ZNK3SST6Output12outputprintfEPKcP13__va_list_tag + 48
[MACHINE:12586] [ 4] 0   libmerlin.so                        0x000000010ba21785 _ZNK3SST6Output6outputEPKcz + 149
[MACHINE:12586] [ 5] 0   libmerlin.so                        0x000000010ba9269a _ZN3SST6Merlin9hr_router13clock_handlerEy + 634
[MACHINE:12586] [ 6] 0   sstsim.x                            0x000000010925845c _ZN3SST5Clock7executeEv + 284
[MACHINE:12586] [ 7] 0   sstsim.x                            0x00000001092bfacb _ZN3SST15Simulation_impl3runEv + 571
[MACHINE:12586] [ 8] 0   sstsim.x                            0x000000010924aef0 _ZL16start_simulationjR15SimThreadInfo_tRN3SST4Core10ThreadSafe7BarrierE + 3024
[MACHINE:12586] [ 9] 0   sstsim.x                            0x00000001092464a4 main + 7492
[MACHINE:12586] [10] 0   dyld                                0x000000011945452e start + 462
[MACHINE:12586] *** End of error message ***

The Segmentation Fault occurs when trying to output the simulation time:

* thread #2, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x8)
    frame #0: 0x00007ff819f5e882 libsystem_pthread.dylib`pthread_mutex_lock + 4
libsystem_pthread.dylib`pthread_mutex_lock:
->  0x7ff819f5e882 <+4>:  cmpq   $0x4d55545a, (%rdi)       ; imm = 0x4D55545A
    0x7ff819f5e889 <+11>: jne    0x7ff819f5e8fe            ; <+128>
    0x7ff819f5e88b <+13>: movl   0xc(%rdi), %eax
    0x7ff819f5e88e <+16>: movl   %eax, %ecx
Target 0: (sstsim.x) stopped.
(lldb) bt
* thread #2, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x8)
  * frame #0: 0x00007ff819f5e882 libsystem_pthread.dylib`pthread_mutex_lock + 4
    frame #1: 0x00007ff819e3fad8 libsystem_c.dylib`flockfile + 31
    frame #2: 0x00007ff819e65ea5 libsystem_c.dylib`vfprintf + 24
    frame #3: 0x0000000100063840 sstsim.x`SST::Output::outputprintf(this=0x0000000100e13898, format="%llu,", arg=0x00007ff7bfefe780) const at output.cc:467:9 [opt]
    frame #4: 0x0000000105a947e5 libmerlin.so`SST::Output::output(this=<unavailable>, format=<unavailable>) const at output.h:204:13 [opt]
    frame #5: 0x0000000105b0569a libmerlin.so`SST::Merlin::hr_router::clock_handler(this=0x0000000100e13640, cycle=<unavailable>) at hr_router.cc:455:37 [opt]
    frame #6: 0x000000010001645c sstsim.x`SST::Clock::execute() [inlined] SST::SSTHandlerBase<bool, unsigned long long>::operator(this=0x0000600000c2ce70, arg=66761)(unsigned long long) at ssthandler.h:188:16 [opt]
    frame #7: 0x0000000100016448 sstsim.x`SST::Clock::execute(this=<unavailable>) at clock.cc:91:14 [opt]
    frame #8: 0x000000010007dacb sstsim.x`SST::Simulation_impl::run(this=0x0000000100d36e20) at simulation.cc:668:27 [opt]
    frame #9: 0x0000000100008ef0 sstsim.x`start_simulation(tid=<unavailable>, info=<unavailable>, barrier=0x00007ff7bfefec20) at main.cc:459:14 [opt]
    frame #10: 0x00000001000044a4 sstsim.x`main(argc=<unavailable>, argv=<unavailable>) at main.cc:940:9 [opt]
    frame #11: 0x000000010039952e dyld`start + 462

I tried running with a variety of options:

$ sst --debug-file="rtr" --output-directory=${PWD} --output-prefix-core="test" <python_file>

All of which caused the seg fault.

I also tried removing the filename argument to the Output constructor and it still failed with the above options.

SST was built with the following flags:

I don't build SST with the enable debug flag, does setting the Output location to a file fall under this caveat:

Some functions are only available if the Core is configured with the --enable-debug flag.

from the docs?

gvoskuilen commented 3 months ago

No, writing to file is not a debug-only feature. The object isn't initialized correctly with that constructor invocation. Either dynamically allocate & invoke the constructor using new or use bufferOccupanciesOutput.initialize("", 0, 0, Output::FILE, filename); instead of the constructor.