hello! I am trying to learn how to do paralell processing. I am baseing this on an example that I saw here:
http://www.codeproject.com/KB/recipes/sseintro.aspx
the one titled "SSETest Demo Project"

I tried to make my own, and don't understand why it isn't working. Here is the code:

// testconsole.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <time.h>
#include <iostream>
#include "windows.h"
#include "math.h"
#include <conio.h>
#include "test.h"
#include <xmmintrin.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
	float *f1 = new float[4];
	float *f2 = new float[4];
	float *result = new float[4];

	for(int i = 0; i < 4; i++)
	{
		f1[i] = (float)i;
		f2[i] = (float)i;
	}
	__m128 *m1 = (__m128*)f1;
	__m128 *m2 = (__m128*)f2;
	__m128 *res = (__m128*)result;
//the next line produces the error: "Unhandled exception at 0x0125149c in 
//testconsole.exe: 0xC0000005: Access violation reading location 0xffffffff."
	*res = _mm_add_ps(*m1, *m2); //access violation reading
	for(int i = 0; i < 4; i++)
	{
		cout << result[i] << endl;
	}
	getch();
	return 0;
}

the strangest part, is even though it produces the error at that line, I do NOT get the error if I comment out the second for loop and the getch(). It simply runs, exits, no error.

can anyone help me out?
Thanks =)

Don't allocate using the operator new, use _aligned_malloc() instead to have the data properly aligned.

thanks for the help! I had a little sample app running, which was working outside the IDE, but not inside..thought it was strange...
it must have been aligning itself by some fluke..LoL

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.