编译我的java程序时出现此错误:
error: Class names, 'EnumDevices', are only accepted if annotation
processing is explicitly requested
1 error
Run Code Online (Sandbox Code Playgroud)
这是java代码(我在Ubuntu上运行它).
import jcuda.CUDA;
import jcuda.driver.CUdevprop;
import jcuda.driver.types.CUdevice;
public class EnumDevices {
public static void main(String args[]) {
CUDA cuda = new CUDA(true);
int count = cuda.getDeviceCount();
System.out.println("Total number of devices: " + count);
for (int i = 0; i < count; i++) {
CUdevice dev = cuda.getDevice(i);
String name = cuda.getDeviceName(dev);
System.out.println("Name: " + name);
int version[] = cuda.getDeviceComputeCapability(dev);
System.out.println("Version: " +
String.format("%d.%d", version[0], …Run Code Online (Sandbox Code Playgroud) 我是cuda的新手.我想将两个2d数组加到第三个数组中.我使用以下代码:
cudaMallocPitch((void**)&device_a, &pitch, 2*sizeof(int),2);
cudaMallocPitch((void**)&device_b, &pitch, 2*sizeof(int),2);
cudaMallocPitch((void**)&device_c, &pitch, 2*sizeof(int),2);
Run Code Online (Sandbox Code Playgroud)
现在我的问题是我不想在我的内核代码中使用这些数组作为扁平的二维数组我希望di使用两个for循环并将结果放在第三个数组中
__global__ void add(int *dev_a ,int *dev_b,int* dec_c)
{
for i=0;i<2;i++)
{
for j=0;j<2;j++)
{
dev_c[i][j]=dev_a[i][j]+dev_b[i][j];
}
}
}
Run Code Online (Sandbox Code Playgroud)
我怎么能在CUDA做到这一点?请告诉我如何以这种方式使用二维阵列?
使用2d-array的内核调用应该是什么?如果可能,请使用代码示例进行说明.
任何机构可以解释为什么我们在gcc中使用-m标志?我运行man gcc命令结果还不清楚是否有任何机构可以在汇编中解释我这个标志的作用?如何使用-m标志其正确的语法?我需要它,因为我通过make命令运行自动生成的makefile,但它显示以下错误:cc1:错误:无法识别的命令行选项"-m"任何人都可以解释这是什么?
在文件处理中,任何人都可以帮我解决这个简单的问题吗?
以下是我的代码:
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ofstream savefile("anish.txt");
savefile<<"hi this is first program i writer" <<"\n this is an experiment";
savefile.close();
return 0 ;
}
Run Code Online (Sandbox Code Playgroud)
它现在运行成功,我想根据我的方式格式化文本文件的输出.
我有:
嗨这是第一个程序我作家这是一个实验
如何使输出文件如下所示:
嗨这是第一个程序
我作家这是一个实验
如何以这种方式格式化输出?
我遇到了C++程序的问题.我想使用在C++文件中的C文件中定义的函数.这是我的C++文件代码:
#include <string>
#include <iostream>
#include <stdio.h>
extern void squre_array();
using namespace std;
int main() {
squre_array();
}
Run Code Online (Sandbox Code Playgroud)
现在这里是我定义的C文件的代码squre_array():
#include <stdio.h>
#include <cuda.h>
__global__ void square_array(float *a, int N)
{
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx<N)
a[idx] = a[idx] * a[idx];
}
void squre_array()
{
float *a_h, *a_d;
const int N = 10;
size_t size = N * sizeof(float);
a_h = (float *)malloc(size);
cudaMalloc((void **) &a_d, size);
for (int i=0; i<N; i++) a_h[i] = …Run Code Online (Sandbox Code Playgroud) 我想用c语言编写一个多线程程序.我使用posix线程库.
我写下面的代码:
#include<stdio.h>
#include<pthread.h>
void *put (int *arg)
{
int i;
//int * p;
// p=(int*)arg;
for(i=0;i<5;i++)
{
printf("\n%d",arg[i]);
}
pthread_exit(NULL);
}
int main()
{
int a[5]={10,20,30,40,50};
pthread_t s;
pthread_create(&s,NULL,put,a);
printf("what is this\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我只想让我的线程只显示数组中的项目.该程序编译时带有以下警告:
tm.c:19: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type
/usr/include/pthread.h:227: note: expected ‘void * (*)(void *)’ but argument is of type ‘void * (*)(int *)’
Run Code Online (Sandbox Code Playgroud)
当我运行程序时,我获得了主线程的输出,但没有存储在数组中的值.
现在谁能告诉我我做错了什么?如何在线程函数中将数组作为参数发送?
如果我只是稍微更改了代码,则编译时警告已解决,更改后的代码如下:
#include<stdio.h>
#include<pthread.h>
void *put (void *arg)
{
int i;
int * p;
p=(int*)arg; …Run Code Online (Sandbox Code Playgroud) 嗨,任何人都可以帮我这个代码.我是c ++的新手
#include <stdio.h>
#include<iostream>
using namespace std;
namespace manish
{
double mean(double a, double b);
}
double mean(double a, double b)
{
return (a+b) / 2;
}
Run Code Online (Sandbox Code Playgroud)
我想为此制作静态库,我使用命令g ++ calc_mean.cpp -o mean.o它给我以下错误
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
Run Code Online (Sandbox Code Playgroud)
谁能告诉我我做错了什么?或者如何为函数创建命名空间,以便可以通过使用其名称空间在其他位置使用它
大家好,有什么可以告诉我什么是gcc的-pedantic标志?就像我们在命令行gcc -pedantic filename.c中使用一样.我不知道为什么我们使用-pedantic flag?请举例说明.
我想知道如何在Ubuntu 10.04中使用c#?
我只想运行一些用c#编写的程序并在Ubuntu上编译它们.任何人都能告诉我怎么做吗?
在我的Windows系统上,它非常简单:我只需安装visual studio,我在记事本中编写程序并在命令提示符下运行它.
谁能告诉我怎样才能让c#在我的Ubuntu系统上运行?
如何在ubuntu中安装c#?
如何在ubuntu中运行c#程序?
嗨,我正在尝试编译一个c ++,程序为julia设置我的源代码如下
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<cpu_bitmap.h>
#include<book.h>
#define DIM 20
using namespace std;
struct cuComplex{
float r;
float i;
cuComplex( float a, float b ) : r(a), i(b){}
float magnitude2( void )
{
return r * r + i * i;
}
cuComplex operator*(const cuComplex& a)
{
return cuComplex(r*a.r - i*a.i, i*a.r + r*a.i);
}
cuComplex operator+(const cuComplex& a)
{
return cuComplex(r+a.r, i+a.i);
}
};
void kernel( unsigned char *ptr )
{
for (int y=0; y<DIM; y++)
{
for ( …Run Code Online (Sandbox Code Playgroud) 我对cuda很新.我在设备仿真模式下在我的ubuntu 10.04上使用cuda.我编写了一个代码来计算以下数组的平方:
#include <stdio.h>
#include <cuda.h>
__global__ void square_array(float *a, int N)
{
int idx = blockIdx.x + threadIdx.x;
if (idx<=N)
a[idx] = a[idx] * a[idx];
}
int main(void)
{
float *a_h, *a_d;
const int N = 10;
size_t size = N * sizeof(float);
a_h = (float *)malloc(size);
cudaMalloc((void **) &a_d, size);
for (int i=0; i<N; i++) a_h[i] = (float)i;
cudaMemcpy(a_d, a_h, size, cudaMemcpyHostToDevice);
square_array <<< 1,10>>> (a_d, N);
cudaMemcpy(a_h, a_d, sizeof(float)*N, cudaMemcpyDeviceToHost);
// Print results
for (int i=0; i<N; …Run Code Online (Sandbox Code Playgroud)