在OpenCL中创建线程网格(Create grid of threads in OpenCL)
我为OpenCL编写了一个内核,我将3D数组的所有元素初始化为 - > i * i * i + j * j * j。 我现在遇到创建线程网格以进行元素初始化(并发)的问题。 我知道我现在只使用3个线程的代码,我该如何扩展呢?
请帮忙。 我是OpenCL的新手,所以任何建议或解释都可能很方便。 谢谢!
这是代码:
_kernel void initialize ( int X; int Y; int Z; _global float*A) { // Get global position in X direction int dirX = get_global_id(0); // Get global position in Y direction int dirY = get_global_id(1); // Get global position in Z direction int dirZ = get_global_id(2); int A[2000][100][4]; int i,j,k; for (i=0;i<2000;i++) { for (j=0;j<100;j++) { for (k=0;k<4;k++) { A[dirX*X+i][dirY*Y+j][dirZ*Z+k] = i*i*i + j*j*j; } } } }
I wrote a kernel for OpenCL where I initialise all the elements of a 3D array to -> i*i*i + j*j*j. I'm now having problems in creating a grid of threads to do the initialisation of the elements (concurrently). I know that the code that I have now only uses 3 threads, how can I expand on that?
Please help. I'm new to OpenCL, so any suggestion or explanation might be handy. Thanks!
This is code:
_kernel void initialize ( int X; int Y; int Z; _global float*A) { // Get global position in X direction int dirX = get_global_id(0); // Get global position in Y direction int dirY = get_global_id(1); // Get global position in Z direction int dirZ = get_global_id(2); int A[2000][100][4]; int i,j,k; for (i=0;i<2000;i++) { for (j=0;j<100;j++) { for (k=0;k<4;k++) { A[dirX*X+i][dirY*Y+j][dirZ*Z+k] = i*i*i + j*j*j; } } } }
原文:https://stackoverflow.com/questions/13590795
最满意答案
如果
DatabaseHandler
不是Activity类,则无需将Activity扩展到它。 您需要创建DatabaseHandler
的参数化构造函数,以将Activity上下文传递给它以创建数据库。 将您的DatabaseHandler类更改为:public class DatabaseHandler implements DatabaseConnector { private SQLiteDatabase database; .... Context context; public DatabaseHandler(Context context){ this.context=context; } @Override public void createConnection() { try { database = context.openOrCreateDatabase("esoftDatabase", MODE_PRIVATE, null); // your code here.... } catch(SQLException sql) { Toast.makeText(context, sql.getMessage(), Toast.LENGTH_LONG).show(); } }
并从表单活动传递活动上下文:
DatabaseConnector databaseConnector = new DatabaseHandler(Form.this); databaseConnector.createConnection();
if
DatabaseHandler
is non Activity class then no need to extends Activity to it. you will need to create a parameterized constructor ofDatabaseHandler
to pass Activity context to it for creating database . change your DatabaseHandler class as:public class DatabaseHandler implements DatabaseConnector { private SQLiteDatabase database; .... Context context; public DatabaseHandler(Context context){ this.context=context; } @Override public void createConnection() { try { database = context.openOrCreateDatabase("esoftDatabase", MODE_PRIVATE, null); // your code here.... } catch(SQLException sql) { Toast.makeText(context, sql.getMessage(), Toast.LENGTH_LONG).show(); } }
and pass Activity Context as from Form Activity :
DatabaseConnector databaseConnector = new DatabaseHandler(Form.this); databaseConnector.createConnection();
相关问答
更多-
如果DatabaseHandler不是Activity类,则无需将Activity扩展到它。 您需要创建DatabaseHandler的参数化构造函数,以将Activity上下文传递给它以创建数据库。 将您的DatabaseHandler类更改为: public class DatabaseHandler implements DatabaseConnector { private SQLiteDatabase database; .... Context context; ...
-
看起来你想要拆分它,所以你的主递归是在TreeNodes上,而不是UBT对象。 public static void inOrder(TreeNode node) { if(node != null) { inOrder(node.getLeft()); System.out.println(node.getData() + " "); inOrder(node.getRight()); } } public static void ...
-
你需要#include
。 编辑: 您可能正在按照一个非常着名的教程为您提供头文件。 这将帮助您然后GLUT退出重新定义错误 You need to #include . edit: You are probably following a very known tutorial that provides a header file for you. This will help you then GLUT exit redefinition error -
您正在使用此代码段添加用户: //Creating Person object User user = new User(firstname, lastname, NIC, email, mobile); //Storing values to firebase ref.child("Users").child("User").setValue(user); 通过此操作,您可以在此位置/Users/User设置数据。 如果要将数据添加到该位置下的新唯一子级,请使用Firebase push()方法: / ...
-
您必须显示更多文件才能确定。 您是否正确导入头文件? 你保存了头文件了吗? 尝试插入显式的self->引用,您可能会收到更明显的错误消息。 另外,尝试预处理实现文件(在Build菜单中),这可能会揭示为什么没有找到ivar。 You would have to show more of the file to be sure. Are you properly importing the header file? Have you saved the header file? Try inserting t ...
-
您可以使用mysqli_error()函数检查mysqli_query()的错误。 出于开发目的,您可以在代码中添加它,即mysqli_query($conn, $sql) or exit(mysqli_error($conn)); 以查看数据库报告的错误。 如果您计划发布应用程序,请稍后将其删除,否则数据库中的错误将向用户公开。 You can check the errors of a mysqli_query() with the function mysqli_error(). For develo ...
-
你需要JOIN UPDATE DATABASE_1.table_1 AS t1 JOIN DATABASE_2.table_2 AS t2 ON t1.ID_1 = t2.DealerID SET t1.ID_1 = t2.ID_2 You need to JOIN UPDATE DATABASE_1.table_1 AS t1 JOIN DATABASE_2.table_2 AS t2 ON t1.ID_1 = t2.DealerID SET t1.ID_1 = t2.ID_2
-
我猜你有类型问题。 你这样说: db.locations.find({_id: 13163}) 在MongoDB shell中找到该文档。 这意味着您在locations集合中有一个文档,其_id是数字 13163 。 如果您使用字符串'13163 ': db.locations.find({_id: '13163'}) 你找不到你的文件。 params[:id]值可能是一个字符串,所以你说: Location.find('13163') 当你想说: Location.find(13163) 如果_ ...
-
您可以在web.config文件中使用转换来自动切换要引用的数据库。 看看这个类似的答案: Web.Config Debug / Release You can use transformations in your web.config file to automatically switch which database you are referencing. Check out this similar answer: Web.Config Debug/Release
-
这是关于通过缓存进行优化的一般性问题。 以下是我对基本相同问题的回答。 即使这个问题提供了大量不同的细节,但它们都没有具体到足以值得一般的非通用答案: 您希望在查询时计算得越多,您想要的视图,计算列和存储或用户例程就越多。 您希望在标准化基准更新时计算得越多,您想要的级联和触发器就越多。 您想要在其他(计划或临时)时间计算得越多,您使用的快照即物化视图和更新的非规范化基础就越多。 你可以结合这些。 无论何时访问数据库,它都可以由存储的例程或其他api启用和限制。 在您可以证明它们足够之前,视图和计算列是最简 ...