MPI Init causes crash in Visual Studio 2010 - visual-studio-2010

I am trying to get an MPI program to run, however it appears to crash on the MPI_INIT call.
Visual studio merely says the exe "has triggered a breakpoint", but doesn't tell me anything else. I am trying to run with 4 processes.
int main(int argc, char **argv) {
int testNumber;
long wcTime, totalWcTime;
float cpuTime, totalCPUTime;
_totalTextLength = 0;
totalWcTime = 0;
totalCPUTime = 0;
MPI_Init(&argc, &argv);
The call stack is as follows:

Related

keyboard interrupt routine visual studio C++ console app

I am using VS 2022 Preview to write a C++ console application. I wish to detect a keyboard hit and have my interrupt handler function called. I want the key press detected quickly in case main is in a long loop and therefore not using kbhit().
I found signal() but the debugger stops when the Control-C is detected. Maybe it is a peculiarity of the IDE. Is there a function or system call that I should use?
Edit: I am vaguely aware of threads. Could I spawn a thread that just watches kbd and then have it raise(?) an interrupt when a key is pressed?
I was able to do it by adding a thread. On the target I will have real interrupts to trigger my ISR but this is close enough for algorithm development. It seemed that terminating the thread was more trouble than it was worth so I rationalized that I am simulating an embedded system that does not need fancy shutdowns.
I decided to just accept one character at a time in the phony ISR then I can buffer them and wait and process the whole string when I see a CR, a simple minded command line processor.
// Scheduler.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <Windows.h>
#include <iostream>
#include <thread>
#include <conio.h>
void phonyISR(int tbd)
{
char c;
while (1)
{
std::cout << "\nphonyISR() waiting for kbd input:";
c = _getch();
std::cout << "\nGot >" << c << "<";
}
}
int main(int argc, char* argv[])
{
int tbd;
std::thread t = std::thread(phonyISR, tbd);
// Main thread doing its stuff
int i = 0;
while (1)
{
Sleep(2000);
std::cout << "\nMain: " << i++;
}
return 0;
}

Dereferencing void* warnings on Xcode

I'm aware of this SO question and this SO question. The element
of novelty in this one is in its focus on Xcode, and in its use of
square brackets to dereference a pointer to void.
The following program compiles with no warning in Xcode 4.5.2, compiles
with a warning on GCC 4.2 and, even though I don't have Visual Studio
right now, I remember that it would consider this a compiler
error, and MSDN and Internet agree.
#include <stdio.h>
int main(int argc, const char * argv[])
{
int x = 24;
void *xPtr = &x;
int *xPtr2 = (int *)&xPtr[1];
printf("%p %p\n", xPtr, xPtr2);
}
If I change the third line of the body of main to:
int *xPtr2 = (int *)(xPtr + 1);
It compiles with no warnings on both GCC and Xcode.
I would like to know how can I turn this silence into warnings or errors, on
GDB and especially Xcode/LLVM, including the fact that function main is int but
does not explicitly return any value (By the way I think -Wall does
the trick on GDB).
that isnt wrong at all...
the compiler doesnt know how big the pointer is ... a void[] ~~ void*
thats why char* used as strings need to be \0-terminated
you cannot turn on a warning for that as it isnt possible to determine a 'size of memory pointer to by a pointer' at compile time
void *v = nil;
*v[1] = 0 //invalid
void *v = malloc(sizeof(int)*2);
*v[1] = 0 //valid
*note typed inline on SO -- sorry for any non-working code

Debugging file scope in Visual Studio

In Visual Studio 2012, I have this uber-simple C++ program:
#include "stdafx.h"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << std::cout;
int i = 1;
return 0;
}
In case you wonder, the "std::cout << std::cout" part is only to show that std:cout can be accessed within the scope of the function - yes, it's meant to print the pointer to the console.
So I set a breakpoint at "int i = 1". When the breakpoint triggers, I want to inspect std::cout from the Command Window (or Immediate Window), so I type:
>Debug.Print std::cout
But it returns the following error:
identifier "std" is undefined
I don't understand why this happens, std should be in the scope of the function which is being executed. The same goes for any other stuff coming from the #include directive, I just can't inspect it using Debug.Print. What do I use in Visual Studio 2012 to inspect EVERYTHING accessible in the execution scope? It seems I can only access local variables with Debug.Print.

c/c++: thread to decrement a variable every 1 second? (in windows)

Well, I was planning to do this:
int seconds = 90;
void *DecreaseSeconds(){
while (seconds>-1)
{
seconds--;
sleep(1000);
}
return NULL;
}
int main(int argc, char *argv[]){
int threadid= pthread_create(&threads[i], NULL, DecreaseSeconds, NULL);
pthread_join(threadid, NULL);
}
Yet I get this dreadful thing when I try to compile on Visual Studio 2008
fatal error C1083: Cannot open include file: 'pthread.h': No such file or directory
I want a way to translate this to windows or make Visual Studio accept my posix thread.
Look up RTL function _beginthreadex.
There is no POSIX thread support on Win32. You need to use Win32 threads or an abstraction that supports both.

How can I programmatically move one Terminal.app window to another space?

If I have several OS-X Terminal.app windows open, how can I move one Terminal window to another space?
I'm happy to use any scripting or programming language to achieve this, but would prefer AppleScript or calls to standard frameworks.
(Note this is to move only one window of an application not all windows.)
Using private calls in Objective-C/C, unofficially listed here
#import <Foundation/Foundation.h>
typedef int CGSConnection;
typedef int CGSWindow;
extern OSStatus CGSMoveWorkspaceWindowList(const CGSConnection connection,
CGSWindow *wids,
int count,
int toWorkspace);
extern CGSConnection _CGSDefaultConnection(void);
int main(int argc, char **argv) {
CGSConnection con = _CGSDefaultConnection();
// replace 2004 with window number
// see link for details on obtaining this number
// 2004 just happened to be a window I had open to test with
CGSWindow wids[] = {2004};
// replace 4 with number of destination space
CGSMoveWorkspaceWindowList(con, wids, 1, 4);
return 0;
}
Standard warnings apply about undocumented APIs: they are subject to breaking.
Based on cobbal's answer, code ported to ruby:
require 'dl';
wid = 2004
dl = DL::dlopen('/System/Library/Frameworks/ApplicationServices.framework/ApplicationServices')
_CGSDefaultConnection = dl.sym("_CGSDefaultConnection", 'I');
CGSMoveWorkspaceWindowList = dl.sym("CGSMoveWorkspaceWindowList", 'IIiII');
con = _CGSDefaultConnection.call();
CGSMoveWorkspaceWindowList.call(con[0], wid, 1, 4);

Resources