我在Ubuntu-64bit 12.04LTS上运行我的笔记本电脑(coreI5).我正试图进入AVX进行一些随机数生成.
在Eclipse-CDT中,我使用Linux GCC创建了一个新的C++"Hello World"项目.我包含了immintrin.h并试图加载__m256类型的东西.
编译器抛出一个错误:
Type '__m256' was not declared in this scope
我查看了immintrin.h并查找了avxintrin.h,以防万一,有拼写错误.当点击avxintrin.h上的open声明时,Eclipse说:
Could not find include file 'avxintrin.h' on include paths
Run Code Online (Sandbox Code Playgroud)
allthow文件可在/usr/lib/gcc/x86_64-linux-gnu/4.6/include/avxintrin.h.
任何人都可以给我提示,该怎么办?关于AVX在线没有很多教程或帮助.我想我必须在编译器选项或类似的东西(!?)中进行一些调整
无论如何这里是代码:
#include <immintrin.h>
#include <iostream>
using namespace std;
int main() {
float out[8];
float a[8] = { 0.0,1.0,2.0,3.0,4.0,5.0,6.0,7};
__m256 test = _mm256_load_ps(&a[0]);
cout << "" << endl; // prints
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这里的错误:
../src/seminar.cpp:15:2: error: '__m256' was not declared in this scope
../src/seminar.cpp:15:9: error: expected ';' before 'test'
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我正在使用ctypes,我正在将一个ndarray传递给一个c函数.它给了我奇怪的输出行为.下面是一些代码:
C-功能:
int foo(int * foo,int N){
for(int i=0;i<N;i++){
cout << "i " << i << " "<< foo[i] << endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
蟒蛇:
from ctypes import *
import numpy as np
bar = cdll.LoadLibrary(".../libtest.so")
N = c_int(10)
check = np.ones(10, dtype=int)
print check
bar.foo(c_int(check.ctypes.data),N)
Run Code Online (Sandbox Code Playgroud)
输出:
[1 1 1 1 1 1 1 1 1 1]
i:0 out:1
i:1 out:0
i:2 out:1
i:3 out:0
i:4 out:1
i:5 out:0
i:6 out:1
i:7 out:0
i:8 out:1
i:9 out:0
Run Code Online (Sandbox Code Playgroud)
一切都对吗?:)
我正在编译 …
早上好,stackoverflow,
我目前正在 AST 之类的东西上实现访问者模式。现在我的问题是,如何迭代元素?
我认为将对象返回给访问者并让访问者从那里开始遍历更符合逻辑。因为当您想以不同的方式遍历对象时,您要保持灵活性。
另一方面,人们可以说,访问者不应该关心对象的结构。因此,如果对象发生变化,您不必也更改访问者。
有什么一般建议可以解决这个问题吗?我有两本关于访问者模式的书,但这两本书都没有讨论如何处理更复杂的节点的问题。
问候脚趾
+我正在尝试使用AVX优化一段python代码.我正在使用ctypes来访问C++函数.有时功能会发生故障,有时甚至不会.我认为它可能与对齐有关?也许任何人都可以帮助我,我有点被困在这里.
Python的代码:
from ctypes import *
import numpy as np
#path_cnt
path_cnt = 16
c_path_cnt = c_int(path_cnt)
#ndarray1
ndarray1 = np.ones(path_cnt,dtype=np.float32,order='C')
ndarray1.setflags(align=1,write=1)
c_ndarray1 = stock.ctypes.data_as(POINTER(c_float))
#ndarray2
ndarray2 = np.ones(path_cnt,dtype=np.float32,order='C');
ndarray2.setflags(align=1,write=1)
c_ndarray2 = max_vola.ctypes.data_as(POINTER(c_float))
#call function
finance = cdll.LoadLibrary(".../libfin.so")
finance.foobar.argtypes = [c_void_p, c_void_p,c_int]
finance.foobar(c_ndarray1,c_ndarray2,c_path_cnt)
x=0
while x < path_cnt:
print c_stock[x]
x+=1
Run Code Online (Sandbox Code Playgroud)
C++代码
extern "C"{
int foobar(float * ndarray1,float * ndarray2,int path_cnt)
{
for(int i=0;i<path_cnt;i=i+8)
{
__m256 arr1 = _mm256_load_ps(&ndarray1[i]);
__m256 arr2 = _mm256_load_ps(&ndarray2[i]);
__m256 add = _mm256_add_ps(arr1,arr2);
_mm256_store_ps(&ndarray1[i],add);
}
return …Run Code Online (Sandbox Code Playgroud) 我正在尝试获取我的程序的已用时间.其实,我想我应该使用yclock()的time.h.但它在程序的所有阶段都保持为零,尽管我添加了10 ^ 5个数字(必须消耗一些CPU时间).我已经搜索过这个问题,看起来,运行Linux的人只有这个问题.我正在运行Ubuntu 12.04LTS.
我要比较AVX和SSE指令,所以使用time_t它不是一个真正的选择.任何提示?
这是代码:
//Dimension of Arrays
unsigned int N = 100000;
//Fill two arrays with random numbers
unsigned int a[N];
clock_t start_of_programm = clock();
for(int i=0;i<N;i++){
a[i] = i;
}
clock_t after_init_of_a = clock();
unsigned int b[N];
for(int i=0;i<N;i++){
b[i] = i;
}
clock_t after_init_of_b = clock();
//Add the two arrays with Standard
unsigned int out[N];
for(int i = 0; i < N; ++i)
out[i] = a[i] + b[i];
clock_t after_add …Run Code Online (Sandbox Code Playgroud)